Also ich habe einen Tag auf diesem einen verbracht und es ist Zeit, um die Profis auf StackOverflow zu wenden.Android: Ändern CardView Layout auf Orientierung ändern
Ich arbeite mit RecyclerView
und CardView
, um Karten anzuzeigen, die Text und ein Bild enthalten. Im Hochformat sieht es gut aus, aber in der Landschaft ist auf beiden Seiten des Bildes Platz, anstatt bündig mit der Kartenkante zu sein. Ich kann die Abmessungen des Bildes nicht ändern, deshalb möchte ich das XML der CardView
über die Ausrichtung ändern, wie Sie es mit einem Fragment oder einer Aktivität tun können.
Ist das möglich und wie könnte dies implementiert werden? Der einzige Gedanke, den ich jetzt habe, wäre, einen anderen ViewHolder
innerhalb meines RecyclerViewAdapter
zu haben, der benutzt wird, wenn ich auf Orientierung suche, suche Landscape. Ich hoffe auf einfachere Lösungen. Vielen Dank im Voraus Jungs.
CardView XML. Beachten Sie, dass die Breite der Karte auf match_parent
festgelegt ist.
<?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>