尽管文本长度大小不同,但我试图将文本直接对齐在每个图标下方。在这张截图中,我希望一切都以这一行为中心:
我曾尝试使用线性和相对布局来获得我想要的内容,但没有成功。这段代码是我现在拥有的,也是最接近我想要的:
<?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"
android:padding="5dp" >
<ImageView
android:id="@+id/grid_item_image"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginRight="10dp"
android:src="@drawable/football_logo" >
</ImageView>
<TextView
android:id="@+id/grid_item_label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@+id/label"
android:layout_weight="1"
android:layout_marginTop="5dp"
android:gravity="center"
android:textSize="15sp">
</TextView>
</LinearLayout>
当然有更好的方法来做到这一点(也许是一个 RelativeLayout 和一个围绕 Textview 的 LinearLayout?)。任何帮助将不胜感激......我对此很陌生。
最佳答案
如果您的图标大小正确(例如 drawable-mdpi 文件夹中的 ~48 像素),那么您可以完全放弃 ImageView
并使用 android:drawableTop="@drawable/football_logo "
在 TextView
中。
如果您想坚持使用嵌套布局方法,请在 ImageView
中使用 android:layout_gravity="center_horizontal"
使 ImageView
居中> 横向。
关于java - 在线性布局中将 TextView 置于 ImageView 正下方,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23437191/