Cardview - 修复视图 - 附加到底部

Cardview - fix view - attach to bottom

我现在的问题:

我需要 "attach" 这两个按钮到底部 - 我不希望它们可以滚动(仅在底部 - 始终可见)。但是我的Edittext需要scrollable,因为有长文本。在android studio 中看起来不错,但在APP 中就不行了。

XML

    <android.support.v7.widget.CardView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    app:cardBackgroundColor="#212121"
    app:cardCornerRadius="8dp"
    app:cardElevation="5dp"
    app:cardMaxElevation="0dp"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="true">

    <EditText
        android:id="@+id/storyTextView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_above="@+id/choiceButton1"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        android:background="@null"
        android:cursorVisible="false"
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:lineSpacingMultiplier="1.2"
        android:paddingBottom="15dp"
        android:paddingLeft="18dp"
        android:paddingRight="18dp"
        android:paddingTop="15dp"
        android:text="You continue your course to Earth. Two days later, you receive a transmission from HQ saying that they have detected some sort of anomaly on the surface of Mars near an abandoned rover. They ask you to investigate, but ultimately the decision is yours because your mission has already run much longer than planned and supplies are low."
        android:textColor="#9E9E9E"
        android:textSize="16sp"
        />

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardBackgroundColor="#212121"
    app:cardCornerRadius="8dp"
    app:cardElevation="5dp"
    app:cardMaxElevation="0dp"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="true">

    <Button
        android:id="@+id/choiceButton1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="1dp"
        android:background="@null"
        android:text="CONTINUE HOME TO EARTH"
        android:textColor="#b71c1c"/>

</android.support.v7.widget.CardView>

<android.support.v7.widget.CardView
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:cardBackgroundColor="#212121"
    app:cardCornerRadius="8dp"
    app:cardElevation="5dp"
    app:cardMaxElevation="0dp"
    app:cardPreventCornerOverlap="false"
    app:cardUseCompatPadding="true">


    <Button
        android:id="@+id/choiceButton2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="1dp"
        android:background="@null"
        android:text="STOP AND INVESTIGATE"
        android:textColor="#b71c1c"/>

</android.support.v7.widget.CardView>

一切都在:

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_story"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#000000"
android:orientation="vertical"
tools:context="com.project.StoryActivity">
</LinearLayout>

IN STUDIO - CLICK

IN APP - CLICK - 可滚动,但 "doesnt fit"

我希望你能理解我的问题,谢谢你们:)

首先,您不需要为图中所示的布局使用cardView(使用相对布局)。 要使用卡片视图, (screen shot is shown here) 你应该添加 编译 'com.android.support:cardview-v7:25.0.1' 到 build.gradle(Module :app) 文件 cardElevation 会做一个边距来得到阴影。

在xml,

<android.support.v7.widget.CardView  xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="500dp"
android:layout_margin="5dp"
card_view:cardBackgroundColor="#212121"
card_view:cardCornerRadius="2dp"
card_view:contentPadding="10dp"
card_view:cardElevation="20dp"
card_view:cardPreventCornerOverlap="true">

    <!--your layout contents ...-->
    <RelativeLayout
        android:id="@+id/activity_story"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#212121">
        <ImageView
            android:id="@+id/StoryImageView"
            android:layout_width="match_parent"
            android:layout_height="200dp"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_alignParentTop="true"
            android:adjustViewBounds="true"
            android:scaleType="fitXY"
            android:src="@mipmap/ic_launcher"/>

        <EditText
            android:id="@+id/storyTextView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/choiceButton1"
            android:layout_alignParentLeft="true"
            android:layout_alignParentStart="true"
            android:layout_below="@+id/StoryImageView"
            android:background="@null"
            android:cursorVisible="false"
            android:focusable="false"
            android:focusableInTouchMode="false"
            android:lineSpacingMultiplier="1.2"
            android:paddingLeft="30dp"
            android:paddingRight="30dp"
            android:paddingTop="15dp"
            android:text="TEXT TEXT TEXT
              TEXT TEXT TEXT
              TEXT TEXT TEXT
              TEXT TEXT TEXT
              TEXT TEXT TEXT
              TEXT TEXT TEXT
              TEXT TEXT TEXT
              TEXT TEXT TEXT
              TEXT TEXT TEXT
              TEXT TEXT TEXT
              "
            android:textColor="#9E9E9E"
            android:textSize="16sp"
            tools:textColor="#9E9E9E"/>

        <Button
            android:id="@+id/choiceButton1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_above="@+id/choiceButton2"
            android:layout_marginTop="3dp"
            android:background="#212121"
            android:text="button1"
            android:textColor="#b71c1c"/>

        <Button
            android:id="@+id/choiceButton2"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_marginBottom="11dp"
            android:layout_marginTop="3dp"
            android:background="#212121"
            android:text="button2"
            android:textColor="#b71c1c"/>
    </RelativeLayout>
</android.support.v7.widget.CardView>

使用 RelativeLayout 而不是 LinearLayout。

到底部按钮,

android:layout_alignParentBottom="true"

第二个按钮

android:layout_above="@+id/bottom_button"

使 EditText 可滚动,

android:inputType="textMultiLine"