I have TextView with some text and ImageView with some icon. I aligned them by baseline:
android:baselineAlignBottom="true"
app:layout_constraintBaseline_toBaselineOf="@ id/penny"
TextView has some text size, but I can't guess the height of ImageView so that the text and the icon are the same height, they are always slightly different. How I can fix it?
CodePudding user response:
You can set top and bottom of image view to top and bottom of textView respectively with height of imageView as 0dp
and scaleType as fitXY.
CodePudding user response:
You can try this one it might be work for you.
Make Linear layout horizontal
with height
as wrap_content
,
Take Textview with your required text size. Take image view with height
as match_parent
and width
as wrap_content
.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Demo Text"
android:textColor="@color/black"
android:textSize="@dimen/_30sdp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_app_logo" />
</LinearLayout>
And for ConstraintLayout layout yu can try this as below.
set android:scaleType="fitXY"
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@ id/tvDemoText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Demo Text"
android:textColor="@color/black"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:textSize="@dimen/_35sdp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="0dp"
android:scaleType="fitXY"
app:layout_constraintTop_toTopOf="@id/tvDemoText"
app:layout_constraintBottom_toBottomOf="@id/tvDemoText"
app:layout_constraintStart_toEndOf="@id/tvDemoText"
android:src="@drawable/material_drawer_ico_menu_down" />
</androidx.constraintlayout.widget.ConstraintLayout>