android相对布局和图像背景

时间:2014-11-23 16:08:33

标签: android image

假设我有相对布局的背景图片。那个图像是一个圆圈,在圆圈内我放置一个带有单个字母的文本视图,如何将文本视图保留在圆圈内,无论如何? 我让图像始终保持相同的分辨率,但有时候字母仍在圆圈之外。

P.S。为高dpi,中等dpi等创建所有不同的布局,无法正常工作

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/ScrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity" >

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:gravity="center" >

    <TextView
        android:id="@+id/Title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#000000"
        android:gravity="center"
        android:text="Majore C "
        android:textColor="#FFFFFF"
        android:textSize="40sp" />

    <RelativeLayout
        android:layout_width="1090dp"
        android:layout_height="1920dp"
        android:background="@drawable/backright3" >

        <TextView
            android:id="@+id/A"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBaseline="@+id/E"
            android:layout_alignBottom="@+id/E"
            android:layout_toRightOf="@+id/E"
            android:background="@drawable/bg_red"
            android:text=" A "
            android:textColor="@color/Red"
            android:textSize="20sp" />

1 个答案:

答案 0 :(得分:0)

试试这个:

<RelativeLayout
    android:layout_width="1090dp"
    android:layout_height="1090dp"
    android:background="@drawable/backright3">

    <TextView
        android:layout_width="1090dp"
        android:layout_height="1090dp"
        android:text="A"
        android:id="@+id/A"
        android:textColor="#ffffff"
        android:textSize="20sp"
        android:gravity="center"
        android:background="@drawable/bg_red"
        android:textColor="@color/Red"
        android:layout_margin="6dp" />
</RelativeLayout>

更新(适用于许多TextView):

<RelativeLayout
            android:layout_width="1090dp"
            android:layout_height="1090dp"
            android:background="@drawable/backright3">

            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="1090dp"
                android:layout_height="1090dp"
                android:layout_margin="6dp"
                android:gravity="center">
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="A"
                    android:id="@+id/A"
                    android:textColor="#ffffff"
                    android:textSize="20sp"
                    android:background="@drawable/bg_red"
                    android:textColor="@color/Red"/>
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="B"
                    android:id="@+id/B"
                    android:textColor="#ffffff"
                    android:textSize="20sp"
                    android:background="@drawable/bg_red"
                    android:textColor="@color/Red"/>

                //Other texts.......

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="Z"
                    android:id="@+id/Z"
                    android:textColor="#ffffff"
                    android:textSize="20sp"
                    android:background="@drawable/bg_red"
                    android:textColor="@color/Red"/>
            </LinearLayout>
</RelativeLayout>

PS:文本数量取决于 textSize 父布局宽度

相关问题