How to create a titled border in Android?

后端 未结 1 1143
耶瑟儿~
耶瑟儿~ 2021-01-12 23:37

has someone an idea how to create a titled border layout like in swing?

On this site i found a trick to generate a rectangle between a object. Maybe this can help me

相关标签:
1条回答
  • 2021-01-13 00:06

    Quick and dirty:

    <?xml version="1.0" encoding="utf-8"?>
    <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" 
    android:color="#000000">
    <View
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:background="@drawable/rectangle"
        android:layout_margin="20dp"
        />
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">
        <TextView 
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:background="#000000"
            android:layout_marginTop="10dp"
            android:text="TITLE!"
            android:textColor="#ffffff"/>
    </RelativeLayout>
    
    </FrameLayout>
    

    And @drawable/rectangle is in a drawable rectangle.xml file like this:

    <?xml version="1.0" encoding="utf-8"?>
    <shape xmlns:android="http://schemas.android.com/apk/res/android" 
        android:shape="rectangle">
    <solid android:color="@android:color/transparent"/>
    <stroke  android:width="2dip" android:color="#ffffff"/>  
    </shape>
    
    0 讨论(0)
提交回复
热议问题