2017-03-10 4 views
0

私は与えられた画像上のボタン、チェックボックスでキーワードタイトル1とキーワードタイトル2ボタンを作成する方法アンドロイドでボタンを作成する方法は?

enter image description here

のようなボタンを作成する際に問題に直面しています。

+0

動的に追加されているのか、静的な2つのボタンだけですか? –

答えて

1

<?xml version="1.0" encoding="utf-8"?> 
    <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 


     <RelativeLayout 
      android:id="@+id/relativeLayout" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_margin="10dp"> 

      <Button 
       android:id="@+id/button" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:padding="10dp" 
       android:text="Keyword Title 1" /> 

     </RelativeLayout> 

     <CheckBox 
      android:layout_width="20dp" 
      android:layout_height="20dp" 
      android:layout_alignEnd="@+id/relativeLayout" 
      android:layout_alignTop="@+id/relativeLayout" /> 


    </RelativeLayout> 
+0

この方法を試しましたが、チェックボックスがボタンの後ろに表示されています –

+0

@PrabhaKaran遅く再生して申し訳ありません。あなたの問題は解決しましたか? – user2025187

+0

私の問題は解決した、私は考えを使用した –

1

コード res/layout/MainLayout.xml下に従ってください、これを試してみてください:

<FrameLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 
     <TextView 
      android:text="@string/keyword_title_1" 
      android:id="@+id/section_label" 
      android:padding="8dp" 
      android:layout_margin="8dp" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/textview_background"/> 
     <CheckBox 
      android:button="@drawable/checkbox_selector" 
      android:layout_gravity="top|end" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 
    </FrameLayout> 

res/drawable/textview_background.xml

<?xml version="1.0" encoding="utf-8"?> 
<shape xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shape="rectangle"> 
    <solid android:color="@color/white"/> 
    <stroke android:color="@color/black" android:width="1dp"/> 
</shape> 

res/drawable/checkbox_selector.xml

<?xml version="1.0" encoding="utf-8"?> 
<selector xmlns:android="http://schemas.android.com/apk/res/android" > 
    <item android:drawable="@drawable/checkbox" 
      android:state_checked="false"/> 
    <item android:drawable="@drawable/checkboxselected" 
      android:state_checked="true"/> 
    <item android:drawable="@drawable/checkbox"/>  
</selector> 
関連する問題