2016-03-03 83 views
-2

我有背景imageview(绿色与3红色圆圈)和3 textview(A,B,C)。 如何将textviews完全放在支持多屏设备,纵向/横向的红色圆圈的中心?textview position backgorund imageview

enter image description here

Eited: 也许我问错了问题。

我的主要问题是:

1 - 我在我的布局已经一个形象的比方像这样:

enter image description here

2 - 我想在精确位置

把TextView的图像

enter image description here

当我测试不同的屏幕尺寸,textviews的位置改变。

enter image description here

+0

见t他在下面回答。 – 2016-03-03 09:17:31

回答

1

试试这个

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

输出是:

enter image description here

+0

谢谢,但我的问题是:我怎么能把textview放在与背景相匹配的位置,并且不会因屏幕大小而改变 – Ali

+0

它的工作原理与您想要的相同。 – 2016-03-03 14:22:45

0

在文本视图XML属性

android:gravity="center" 

,使圆xml文件宽度作为经纱含量

width = "wrap_content"