Textview does not align the center below the image

the textview is not aligned correctly under the image in the watch list, see screenshot

image

represents the center of the show below some image, another image is shown from right to right. I want to show the center of the text below each image.

holder.txtText = (TextView) convertView.findViewById(R.id.title2); holder.imgThumb = (ImageView) convertView.findViewById(R.id.image2); androidAQuery.id(holder.imgThumb). image(fifthscreen.Category_image.get(position), false, false); <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="vertical" > <ImageView android:id="@+id/image2" android:layout_width="90dp" android:layout_height="70dp" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:background="#000000" android:padding="5dp" android:scaleType="fitXY" android:src="@drawable/icon" /> <TextView android:id="@+id/title2" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginLeft="30dp" android:gravity="center_horizontal" android:textColor="#000" /> </LinearLayout> 
+4
source share
3 answers

you use android:layout_width="wrap_content" , which will consume the maximum width as the Length text of your TextView ,

Because of this, android:gravity="center_horizontal" has no effect

Make android:layout_width="90dp" of TextView equal to your ImageView

Use this

 <TextView android:id="@+id/title2" android:layout_width="90dp" <!-- Same width as your ImageView has --> android:layout_height="wrap_content" android:textColor="#000" android:gravity="center_horizontal" /> 
+1
source

First of all, give the TextView width 90dp because you provided it with an ImageView, so make the TextView fit the size of the ImageView. Then set android: layout_gravity = "center_horizontal".

+2
source

Set TextView width 90dp instead of Wrap_content , just like ImageView , and layout_gravity is android:layout_gravity="center_horizontal" .

Regards

0
source

Source: https://habr.com/ru/post/1501838/


All Articles