[英]Fit TextView under ImageView
I have 2 rows of "buttons" which are composed of a vertical LinearLayout
of an ImageView
and a TextView
. 我有两行“按钮”,它们由
ImageView
和TextView
的垂直LinearLayout
组成。 The problem I'm having right now is trying to set the ImageView
aspect ratio without hardcoding its dimensions. 我现在遇到的问题是尝试设置
ImageView
宽高比,而无需对其尺寸进行硬编码。
I have already tried playing with the layout weights but it still forces the TextView to be partially cut off. 我已经尝试过使用布局权重,但是它仍然迫使TextView被部分切除。
The xml structure I have is 2 horizontal LinearLayouts
and each button is described above. 我拥有的xml结构是2个水平
LinearLayouts
,每个按钮如上所述。
I've included a picture of my problem. 我已附上我的问题的照片。 You can see the first button is forcing the
TextView
out of the bounds. 您可以看到第一个按钮迫使
TextView
超出范围。 The rest of the buttons you see are hardcoded dimensions, but I don't want to do that because smaller screen sizes won't work. 您看到的其余按钮都是硬编码的尺寸,但是我不想这样做,因为较小的屏幕尺寸不起作用。
Here is my layout for one button: 这是我一个按钮的布局:
<LinearLayout
android:gravity="center_horizontal"
android:layout_weight="1"
android:padding="5dp"
android:orientation="vertical"
android:layout_width="0dip"
android:layout_height="match_parent">
<ImageView
android:id="@+id/setting_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@null"
android:clickable="true"
android:onClick="openSettings"
android:src="@drawable/menu" />
<TextView
android:id="@+id/setting_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Settings"
android:textAlignment="center"
android:textColor="@android:color/white"
android:autoSizeTextType="uniform" />
</LinearLayout>
尝试使用较小尺寸的图像。
Try using a RelativeLayout and setting the TextView as anchor for the image: 尝试使用RelativeLayout并将TextView设置为图像的锚点:
<RelativeLayout
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:padding="5dp">
<TextView
android:id="@+id/setting_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
android:text="Settings"
android:textAlignment="center"
android:textColor="@android:color/white"
android:autoSizeTextType="uniform" />
<ImageView
android:id="@+id/setting_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@id/setting_text"
android:scaleType="centerInside"
android:adjustViewBounds="true"
android:background="@null"
android:clickable="true"
android:onClick="openSettings"
android:src="@drawable/menu" />
</RelativeLayout>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.