LinearLayout にコーナー半径を適用する方法 質問する

LinearLayout にコーナー半径を適用する方法 質問する

丸い境界線のあるレイアウトを作成したいです。 で特定のサイズの半径を適用するにはどうすればよいですかLinearLayout?

ベストアンサー1

描画可能フォルダにXMLファイルを作成できます。たとえば、次のようにします。shape.xml

shape.xml

<shape
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle"   >
    
    <solid
        android:color="#888888" >
    </solid>
    
    <stroke
        android:width="2dp"
        android:color="#C4CDE0" >
    </stroke>
     
    <padding
        android:left="5dp"
        android:top="5dp"
        android:right="5dp"
        android:bottom="5dp"    >
    </padding>
     
    <corners
        android:radius="11dp"   >
    </corners>
     
</shape>

タグ<corner>は特定の質問用です。

必要に応じて変更を加えます。

そしてあなたのwhatever_layout_name.xml

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:layout_margin="5dp"
    android:background="@drawable/shape"    >
</LinearLayout>

これは私がアプリで通常行うことです。

おすすめ記事