0

所以,我使用 cardview 在我的 android 应用程序的一个页面中创建一个片段页面。我正在使用 cardview 来获得一个整洁的方形布局,但是对于长文本,对于最后一段,它被 1 行截断,而且 layout_marginbottom 似乎也不起作用。发生什么事?

这是我的 fragmentpage.xml

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:background="#ffffff" >

        <android.support.v7.widget.CardView
            xmlns:card_view="http://schemas.android.com/apk/res-auto"
            android:id="@+id/card_view"
            android:layout_margin="8dp"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:clickable="false"
            android:foreground="?android:attr/selectableItemBackground"
            card_view:cardCornerRadius="0dp">

            <ScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent">
                <LinearLayout android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_marginTop="20dp"
                    android:layout_marginBottom="20dp"
                    android:orientation="vertical"
                    android:layout_marginLeft="10dp"
                    android:layout_marginRight="10dp">

                    <ImageView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:src="@drawable/ifgf_logo" />

                    <TextView android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_gravity="center_horizontal|center"
                        android:gravity="center"
                        android:textSize="25sp"
                        android:layout_centerInParent="true"
                        android:textColor="#626262"
                        android:text="Title 1"/>

                    <TextView android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_gravity="center_horizontal|center"
                        android:gravity="center"
                        android:textSize="15sp"
                        android:layout_centerInParent="true"
                        android:textColor="#626262"
                        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."/>

                    <TextView android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_gravity="center_horizontal|center"
                        android:gravity="center"
                        android:textSize="25sp"
                        android:layout_centerInParent="true"
                        android:textColor="#626262"
                        android:text="Title 2"/>

                    <TextView android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_gravity="center_horizontal|center"
                        android:gravity="center"
                        android:textSize="15sp"
                        android:layout_centerInParent="true"
                        android:textColor="#626262"
                        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."/>

                    <TextView android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_gravity="center_horizontal|center"
                        android:gravity="center"
                        android:textSize="25sp"
                        android:layout_centerInParent="true"
                        android:textColor="#626262"
                        android:text="Title 3"/>

                    <TextView android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_gravity="center_horizontal|center"
                        android:gravity="center"
                        android:textSize="15sp"
                        android:layout_centerInParent="true"
                        android:textColor="#626262"
                        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."/>

                    <TextView android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_gravity="center_horizontal|center"
                        android:gravity="center"
                        android:textSize="25sp"
                        android:layout_centerInParent="true"
                        android:textColor="#626262"
                        android:text="Title 4"/>

                    <TextView android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_marginTop="20dp"
                        android:layout_gravity="center_horizontal|center"
                        android:gravity="center"
                        android:textSize="15sp"
                        android:layout_centerInParent="true"
                        android:textColor="#626262"
                        android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."/>
                </LinearLayout>
            </ScrollView>
        </android.support.v7.widget.CardView>
</RelativeLayout>

这是我向下滚动之前和向下滚动之后的屏幕截图。顶部正确地有顶部边距,但底部似乎没有任何边距,并且还切断了一些文本。

在此处输入图像描述 在此处输入图像描述

4

1 回答 1

0

您可以像这样插入一个空白视图:

 <View 
      android:layout_width="fill_parent"
      android:layout_height="20dp" /> 

// 根据您的要求设置高度

将此代码放入滚动视图的布局中(在 start 和 end 处)。

这样做:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical"
    android:padding="30dp" >

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="match_parent" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:layout_marginTop="20dp"
            android:orientation="vertical" >

            <View
                android:layout_width="fill_parent"
                android:layout_height="20dp" />

            <ImageView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/ic_launcher" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_gravity="center_horizontal|center"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:text="Title 1"
                android:textColor="#626262"
                android:textSize="25sp" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_gravity="center_horizontal|center"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&apos;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
                android:textColor="#626262"
                android:textSize="15sp" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_gravity="center_horizontal|center"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:text="Title 2"
                android:textColor="#626262"
                android:textSize="25sp" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_gravity="center_horizontal|center"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&apos;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
                android:textColor="#626262"
                android:textSize="15sp" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_gravity="center_horizontal|center"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:text="Title 3"
                android:textColor="#626262"
                android:textSize="25sp" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_gravity="center_horizontal|center"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&apos;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
                android:textColor="#626262"
                android:textSize="15sp" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_gravity="center_horizontal|center"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:text="Title 4"
                android:textColor="#626262"
                android:textSize="25sp" />

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerInParent="true"
                android:layout_gravity="center_horizontal|center"
                android:layout_marginTop="20dp"
                android:gravity="center"
                android:text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry&apos;s standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum."
                android:textColor="#626262"
                android:textSize="15sp" />

            <View
                android:layout_width="fill_parent"
                android:layout_height="20dp" />
        </LinearLayout>
    </ScrollView>

</RelativeLayout>

希望这可以帮助... :)

于 2015-01-14T06:37:20.667 回答