私はAndroidアプリを開発しています。私のアプリでは、イメージにオーバーレイを設定しようとしています。しかし、相対レイアウト内のビューのサイズは、withとheightで常に0です。match_parentをwidthとheightの両方に設定しても、常にゼロになります。下記の私のシナリオをご覧ください。AndroidのRelativeLayoutで表示幅と高さが常にゼロです
これはこれは
あなたが見ることができるように結果である
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginTop="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_width="match_parent"
android:id="@+id/di_card_container"
android:layout_height="wrap_content">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/di_iv_image"
android:scaleType="centerCrop"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<RelativeLayout
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:id="@+id/di_name_container"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<View
android:layout_centerInParent="true"
android:background="@color/blue"
android:id="@+id/destination_item_overlay"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<TextView
android:padding="10dp"
android:textSize="15dp"
android:textColor="@color/white"
android:id="@+id/di_tv_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</RelativeLayout>
</RelativeLayout>
</android.support.v7.widget.CardView>
私のXMLレイアウトで幅や視野の高さがあるため、名前には青色の背景が相対ではありませんレイアウトはゼロです。しかし、以下のように明示的に幅と高さを設定すると、動作しています。
<View
android:layout_centerInParent="true"
android:background="@color/blue"
android:id="@+id/destination_item_overlay"
android:layout_width="300dp"
android:layout_height="30dp"/>
ただし、すべてのデバイスと互換性がありません。なぜwithとheightは常にゼロですか?私はそのビューをプログラムで制御する必要があるので、そのビューを追加しています。その背景ビューの幅と高さを親に合わせて設定するにはどうすればよいですか?
感謝を。それは完璧に働いた。 –
Cool。喜んで助けになる – Shaishav