簡體   English   中英

背景圖像視圖的文本視圖位置

[英]textview position by background imageview

我有背景圖像視圖(綠色帶 3 個紅色圓圈)和 3 個文本視圖(A、B、C)。 如何將文本視圖准確地放在支持多屏幕設備、縱向/橫向的紅色圓圈的中心?

在此處輸入圖片說明

編輯:也許我問錯了問題。

我的主要問題是:

1- 我的布局中有一個圖像,例如這樣:

在此處輸入圖片說明

2- 我想將 textview 放在圖像上的確切位置

在此處輸入圖片說明

當我在不同的屏幕尺寸上測試時,textviews 的位置發生了變化。

在此處輸入圖片說明

嘗試這個

活動_main.xml

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivity">


<TextView
    android:id="@+id/num_txt"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_marginTop="10dp"
    android:layout_marginLeft="20dp"
    android:background="@drawable/bg_red"
    android:gravity="center"
    android:text="A"
    android:textColor="#000000"
    android:textSize="20dp" />

<TextView
    android:id="@+id/num_txt2"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_marginTop="30dp"
    android:layout_marginLeft="100dp"
    android:background="@drawable/bg_red"
    android:gravity="center"
    android:text="B"
    android:textColor="#000000"
    android:textSize="20dp" />
<TextView
    android:id="@+id/num_txt3"
    android:layout_width="50dp"
    android:layout_height="50dp"
    android:layout_marginTop="100dp"
    android:layout_marginLeft="50dp"
    android:background="@drawable/bg_red"
    android:gravity="center"
    android:text="C"
    android:textColor="#000000"
    android:textSize="20dp" />

保存在可繪制的bg_red.xml 中

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="oval">
        <corners android:radius="10dip"/>
        <stroke android:color="#FF0000" android:width="5dip"/>
        <solid android:color="#FF0000"/>
    </shape>

輸出是:

在此處輸入圖片說明

在文本視圖 xml 屬性中

android:gravity="center"

並將圓形 xml 文件寬度設為扭曲內容

width = "wrap_content"

暫無
暫無

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

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