[英]textview position by background imageview
嘗試這個
活動_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.