I have a constraint layout which displays like an image view but it contains multiple views with the width set as wrap_content. The constraint layout is put inside horizontal scroll bar. My problem is,.. for the small dpi phones, the width of layout becomes big so I have to scroll to see the full layout. But I can fix it using this in the xml of constraint layout by adding
android:scaleX="0.7"
android:scaleY="0.7"
But the problem is, for the high dpi phones, the layout becomes very small and there are blank spaces appear around the layout. So i think I need to adjust the scaleX and scaleY to programmatically so that it will become a variable to adjust the layout scale for different screensizes. How to adjust this scaleX and Y in java code programmatically according to the screen dpi?
example,
for the 420dpi phones, the scales should be 0.8
for the 320dpi phones, the scales should be 0.6 or lower, etc...
but using these values with if statement will not accurate for all phones. I want an accurate variable float value of scale to fit the screen for every dpi displays. How to get this float value of scaleX and scaleY from the screen dpi. Please. (if possible, i don't want to use Horizontal scrollview. I want the scale of constraint layout to fit the width of screen only. And also I can't use different layouts in this case.)
This is my xml for this
<androidx.core.widget.NestedScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginBottom="55dp"
android:fillViewport="true"
android:visibility="visible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintlayoutprintcard"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="5dp"
android:layout_marginStart="5dp"
android:layout_marginTop="5dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<HorizontalScrollView
android:id="@+id/horizontalscrollview"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#00FFFFFF"
android:fillViewport="true"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintlayoutprint"
android:layout_width="500dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="@color/colorWhite1"
android:scaleX="0.8"
android:scaleY="0.8"
android:visibility="visible"
tools:ignore="ExtraText">
</androidx.constraintlayout.widget.ConstraintLayout>
</HorizontalScrollView>
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.core.widget.NestedScrollView>