以下のスクリーンショットの下で、ImageView
を使用してCardView
にイメージを挿入しています。CardView内のImageViewの空白を取り除く方法
問題は、私はイメージの下の空きスペースを取り除くことができないようです。 (明るい青色で強調表示)
私はa solution that worksを試しましたが、画像の高さを明示的に指定する必要があります。なぜなら、ソースはさまざまな場合があり、画像を柔軟に拡大/縮小する必要があるからです(同じアスペクト比で)カードの幅に応じて。ここで
はスクリーンショットです:
そしてここでは、コードスニペットです:
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
card_view:cardElevation="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="7dp">
<TextView
android:id="@+id/caption_text"
android:text="Hello World!"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:scaleType="fitStart"
android:layout_below="@id/caption_text"
android:src="@drawable/food"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
ので、CardView
が自動的に画像を包み込むようにするどのような方法があるが、(残さずに空のスペース)を指定し、イメージの高さを明示的に指定しないでください。
あなたの解決策は動作しません。 btw私はスクリーンショットを変更しました。以前のバージョンでは明るい青色のハイライトが間違っていたためです。 –
@MosesAprico上記の更新を確認してください。 – Shaishav
愚かなアンドロイド・デュ。とにかく彼らはどうにかデフォルトとして奇妙な設定を作ることができます。 :/ –