Android在背景边框图像中添加文本

时间:2016-12-07 06:13:38

标签: android

how to put text in border

如何在android

的边框上添加文字

有些人这样认为 Text in Border CSS HTML

2 个答案:

答案 0 :(得分:0)

在从HERE

复制的布局中使用此布局
 <?xml version="1.0" encoding="utf-8"?>
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:background="@android:color/white">

        <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
            android:background="@android:color/white" android:padding="5dp"
            android:text="Testing"
            android:layout_marginLeft="30dp" android:textColor="@android:color/black" />

        <RelativeLayout
            android:layout_width="fill_parent" android:layout_height="fill_parent"
            android:background="@drawable/frame"
            android:orientation="vertical" android:padding="20dp"
            android:layout_centerVertical="true"
            android:layout_centerHorizontal="true">

            <TextView android:layout_width="wrap_content" android:layout_height="wrap_content"
                android:text="Main Content" android:layout_centerInParent="true" />
        </RelativeLayout>
    </RelativeLayout>

在drawable

中创建frame.xml
<shape xmlns:android="schemas.android.com/apk/res/android">
<stroke android:width="1px" android:color="@color/black" /><padding android:left="1dp" 
android:top="1dp" 
android:right="1dp" 
android:bottom="1dp" />
</shape>

答案 1 :(得分:0)

你也可以用非道德的方式来实现这一点......实现这个的快捷方式....试试这个......

 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff" >

    <EditText
        android:id="@+id/edittext"
        android:layout_width="fill_parent"
        android:layout_height="90dp"
        android:layout_alignLeft="@+id/button"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="61dp"
        android:background="@drawable/border"
        android:ems="10"
        android:inputType="text"
        android:text="hia" />

    <Button
        android:id="@+id/button1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginLeft="20dp"
        android:layout_marginTop="46dp"
        android:background="#ffffff"
        android:clickable="false"
        android:text="vvvv"
        android:textSize="24dp" />

</RelativeLayout>
相关问题