簡體   English   中英

如何在Android布局中的IMAGEVIEW上放置TEXTVIEW中心

[英]How to put a TEXTVIEW center on a IMAGEVIEW in Android Layout

我想知道,如何將文本中心放在圖像上,這是示例圖像,

在此輸入圖像描述

我嘗試了以下代碼,但它不能正常工作,

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

您可以嘗試使用背景圖像創建文本視圖。 就像是:

        <TextView 
        android:id="@+id/textview1"
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:gravity="center"
        android:textColor="#000000"
        android:textStyle="bold"
        android:text="Random Text"
        android:background="@drawable/image"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>    

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM