android - 如何在 Android 布局中将 TEXTVIEW 中心放在 IMAGEVIEW 上

标签 android android-layout android-listview

我想知道,如何在图片上放置一个文本中心,这里是示例图片,

enter image description here

我尝试了下面的代码,但它不能正常工作,

<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/

相关文章:

Android Jetpack 撰写 : Keyboard changing from numeric to alphabets after modifying input text

android - BottomSheets 的侧滑画廊?

java - 保存动态创建的复选框的状态

android 在默认图库查看器中显示图像

Android - ListView滚动太慢

android - 如何制作实现可点击的自定义 RelativeLayout?

android - 在 Android 中更改选定列表项的布局

java - boolean 函数返回无值

java - Android Java - 广播接收器 - 应用程序通知

android - 用于音频的 MediaExtractor,得到意外的音频