我想知道,如何在图片上放置一个文本中心,这里是示例图片,
我尝试了下面的代码,但它不能正常工作,
<LinearLayout
android:layout_width="100dip"
android:layout_height="fill_parent"
android:layout_marginRight="5dip"
android:gravity="center"
android:orientation="vertical" >
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/points"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="+2"
android:textColor="#fff"
android:textSize="16sp" />
<ImageView
android:id="@+id/btbt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btbt" />
</TableRow>
</TableLayout>
</LinearLayout>
请告诉我一个好的解决方案。
最佳答案
您可以为此使用图像按钮 我更喜欢使用 imagebutton .. 或者 按此顺序放置此 ImageView
<TableRow
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<Relativelayout android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:id="@+id/points"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:text="+2"
android:textColor="#fff"
android:textSize="16sp" />
<ImageView
android:id="@+id/btbt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/btbt" />
</Relativelayout >
</TableRow>
关于android - 如何在 Android 布局中将 TEXTVIEW 中心放在 IMAGEVIEW 上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22270947/