2016-09-13 10 views
0

カスタムボタン(res/drawableのpngを使用する)上にテキストビューを表示するにはどうすればよいですか?カスタムレイアウトのボタンにテキストビューを表示するにはどうすればよいですか?

私はアンドロイドウェアのウェアラブルスクエアウォッチのUIを作成しようとしています。 レイアウトを構成したい2つのボタンの外観を変更するカスタム背景を作成しました。 レイアウトにテキストビューを追加すると、常にButtonの下に配置され、決して表示されません。

私はすでに解決策を探していましたが、通常、問題は人々が間違ったレイアウトを使用していることです。私はフレームと相対レイアウトの両方を試していますが、どちらのレイアウトも互いのコンテンツを積み重ねるべきですが、そうではありません。

私はボタン自体のテキストフィールドを使用することができますが、私はむしろ内部に書かれたテキストの専用のテキストビューを持っています。しかし、私は問題が何であるか把握できません。

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


    <TextView 
     android:id="@+id/textView" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Text" 
     android:textColor="#ffffff" 
     android:layout_gravity="center"/> 

    <Button 
     android:id="@+id/wearable_alarm_button" 
     android:layout_width="wrap_content" 
     android:background="@drawable/red_button" 
     android:layout_height="wrap_content" /> 

    <Button 
     android:layout_width="130dp" 
     android:layout_height="120dp" 
     android:background="@drawable/blue_button" 
     android:id="@+id/wearable_timer_button" 
     android:layout_gravity="right|bottom" /> 
</FrameLayout> 

.

+0

あなたの青と赤のボタンも共有します – Anjali

+0

なぜあなたはそれを望んでいるのかわかりません。 [red_button](http://imgur.com/utv57zB) [blue_button](http://imgur.com/iWKNvGR) – fogx

答えて

1

それはボタンの上のあなたのTextViewが表示されます

<Button 
    android:id="@+id/wearable_alarm_button" 
    android:layout_width="wrap_content" 
    android:background="@drawable/red_button" 
    android:layout_height="wrap_content" /> 

<Button 
    android:layout_width="130dp" 
    android:layout_height="120dp" 
    android:background="@drawable/blue_button" 
    android:id="@+id/wearable_timer_button" 
    android:layout_gravity="right|bottom" /> 
<TextView 
    android:id="@+id/textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Text" 
    android:textColor="#ffffff" 
    android:layout_gravity="center"/> 

ようタグの後タグを追加します。

+0

あなたはそれが何を意味するのかよく分かりません。 framelayoutのスタッキングプロパティを使用することを意味しますか?これは問題を解決するものではなく、ボタンの前後に配置しようとしました。 サンプルコードをxmlファイルに入れても問題は解決されません。 – fogx

関連する問題