2017-07-27 8 views
0

Viewの高さがTextViewの高さになる半透明の赤いViewとTextViewをRelativeLayout内に作成しようとしましたが、半透明の赤表示:android:layout_alignTopはandroid:layout_alignBottomと似ていません

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<View 
    android:background="#FF0000" 
    android:alpha="0.5" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignBottom="@id/textView"/> 
<TextView 
    android:id="@+id/textView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="TEST" 
    android:textSize="50dp" 
    android:textColor="#000000"/> 
</RelativeLayout> 

enter image description here

が、私はそれを少し変更したい:のTextViewの上に表示を入れて、他の人が変更されないまま、私はandroid:layout_alignTopに変更android:layout_alignBottomを試してみました:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent"> 
<View 
    android:background="#FF0000" 
    android:alpha="0.5" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignTop="@id/textView"/> 
<TextView 
    android:id="@+id/textView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:text="TEST" 
    android:textSize="50dp" 
    android:textColor="#000000"/> 
</RelativeLayout> 

が、今ViewTextViewの高さに従っていないようです:

enter image description here

何が問題で、どのように私はそれを修正することができますか?

+0

xmlだけではできないと思います。 'TextView'の上に' View'を置く必要がある場合、その高さの位置合わせを行うことはできません。 – BakaWaii

答えて

0

ビューにandroid:layout_alignBottom="@+id/textView"を追加します。 EG-

<View 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignTop="@id/textView" 
     android:layout_alignBottom="@+id/textView" 
     android:alpha="0.5" 
     android:background="#FF0000" /> 
0

私はそれを少し変更したい:上を言って、あなたがTextViewの頂上を意味する場合

のTextViewビューを入れて、他は変わりませんz軸に関しては、あなたは間違った方向にいる。

あなたができることは、レイアウト内のビューの順序を変更することです。最初にレイアウトされたレイアウトが最初にレイアウトされ、次にレイアウトされたレイアウトが次にレイアウトされます。

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

    <TextView 
     android:id="@+id/textView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:text="TEST" 
     android:textSize="50dp" 
     android:textColor="#000000"/> 

    <View 
     android:background="#FF0000" 
     android:alpha="0.5" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignBottom="@+id/textView"/> 
</RelativeLayout> 
関連する問題