私はこの1日を過ごしたので、StackOverflowの賛否両論に目を向ける時です。Android:オリエンテーションの変更でCardViewのレイアウトを変更
テキストと画像を含むカードを表示するには、RecyclerView
とCardView
と一緒に作業しています。肖像画ではそれは素晴らしいように見えますが、風景の中には、カードの端と同じ高さではなく、画像の両側にスペースがあります。私は、イメージの寸法を変更することはできませんので、フラグメントやアクティビティのように、向きの変更についてCardView
のXMLを変更したいと思います。
これは可能ですか?どのように実装できますか?私が今考えているのは、RecyclerViewAdapter
の中に別のViewHolder
を持っていて、向きを確認するときに使用される風景です。私はもっと簡単なソリューションを望んでいます。先輩に感謝します。
CardView XML。カードの幅はmatch_parent
に設定されています。
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:id="@+id/placeCard"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
card_view:cardCornerRadius="4dp"
card_view:cardElevation="8dp"
android:background="@drawable/ripple"
android:clickable="true"
android:focusable="true"
android:foreground="?selectableItemBackground">
<RelativeLayout
android:id="@+id/rippleForeground"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/articleImageView"
android:layout_width="match_parent"
android:layout_height="228dp" />
<RelativeLayout
android:id="@+id/infoRelativeLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/paletteView"
android:background="@android:color/white"
android:paddingRight="8dp"
android:paddingBottom="8dp"
android:paddingLeft="8dp">
<TextView
android:id="@+id/titleTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginTop="8dp"
android:text="@string/placeholder"
android:textStyle="bold"
android:textAppearance="?android:attr/textAppearanceMedium"/>
<TextView
android:id="@+id/abstractTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/titleTextView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="8dp"
android:text="@string/placeholder" />
<!--<TextView
android:id="@+id/timeTextView"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
android:text="@string/placeholder"
android:textColor="@color/colorSecondaryText"/>-->
<TextView
android:id="@+id/globalTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/abstractTextView"
android:layout_alignParentBottom="true"
android:padding="8dp"
android:gravity="center"
android:text="@string/placeholder"
android:textStyle="bold"
android:textColor="@color/colorSecondaryText"/>
</RelativeLayout>
<View
android:id="@+id/paletteView"
android:layout_width="match_parent"
android:layout_below="@id/articleImageView"
android:layout_height="4dp"
android:layout_marginTop="12dp"/>
</RelativeLayout>