В моем приложении для Android я являюсь фрагментом, в котором я хочу отображать CardViews. Эти оба CardViews должны заполнять всю площадь экрана. Изображение, которое отображается внутри элемента карты, является очень большим изображением, и оно должно быть сжато для отображения внутри карты. Я не могу заполнить всю область экрана следующим кодом и сделать доступным для просмотра карты.Fill CardView внутри области экрана
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.myFirstApp.app1.cardviewFragment">
<!-- TODO: Update blank fragment layout -->
<!--<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scrollbars="horizontal"
android:background="@android:color/holo_blue_bright" ></android.support.v7.widget.RecyclerView>-->
<LinearLayout android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="10dp" android:background="@color/colorAccent">
<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:id="@+id/card_view1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="8dp"
android:layout_marginBottom="16dp">
<LinearLayout android:orientation="vertical"
android:id="@+id/display_card_view_linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/display_name1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="13sp"
android:text="@string/app_name"
android:textColor="#ffffff"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:background="#1976D2"/>
<ImageView
android:id="@+id/display_image1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/action_settings"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/display_information1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="13sp"
android:text="Card View Footer"
android:textColor="#ffffff"
android:layout_below="@+id/display_image1"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:background="#1976D2"/>
</LinearLayout>
</android.support.v7.widget.CardView>
<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:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardUseCompatPadding="true"
card_view:cardCornerRadius="8dp"
android:layout_marginBottom="16dp">
<LinearLayout android:orientation="vertical"
android:id="@+id/display_card_view_linearLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/display_name2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="13sp"
android:text="@string/app_name"
android:textColor="#ffffff"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:background="#1976D2"/>
<ImageView
android:id="@+id/display_image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/action_settings"
android:scaleType="fitCenter" />
<TextView
android:id="@+id/display_information2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:textSize="13sp"
android:text="Card View Footer"
android:textColor="#ffffff"
android:layout_below="@+id/display_image2"
android:paddingBottom="8dp"
android:paddingTop="8dp"
android:gravity="center_horizontal"
android:layout_alignParentBottom="true"
android:background="#1976D2"/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout>
</FrameLayout>
Как я могу сделать CardView заполнять всю область и сделать ее доступной?
Спасибо заранее,
IamHuM
Предлагаю вам расширить свой ответ, чтобы включить объяснение, почему это должно сработать. – sds
У меня нет идеи, если эта работа для вас, но в одном из моих приложений она сработала, вы можете здесь ввести код [GitHub code] (https://github.com/brunomassa/LuxVilla) в макете настроек настроек, я использую полная ширина вид. –
в порядке, поэтому, пожалуйста, объедините свой комментарий в свой ответ (нажмите «изменить»). – sds