百分位数不得以高度和保证金为百分比相关的属性



我使用相对布局百分比来定义卡视图的布局。定义宽度和水平余量属性时,它可以正常工作。但是,在百分比中定义高度和余量底部/底部对布局没有影响。这是我的卡片布局的XML:

<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_margin="10dp"
    app:cardBackgroundColor="@color/cardview_light_background"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/exam_card">
    <android.support.percent.PercentRelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:textStyle="bold"
            android:textColor="@color/colorPrimaryDark"
            app:layout_widthPercent="60%"
            android:layout_height="wrap_content"
            android:textSize="30sp"
            android:id="@+id/exam_name"/>
        <TextView
            app:layout_marginLeftPercent="58.5%"
            app:layout_marginStartPercent="58.5%"
            android:textColor="@color/colorPrimary"
            android:textStyle="bold"
            app:layout_widthPercent="20%"
            android:id="@+id/from_test_date"
            android:layout_height="wrap_content"
            android:textSize="28sp"
            />
        <TextView
            app:layout_widthPercent="20%"
            app:layout_marginLeftPercent="56%"
            app:layout_marginStartPercent="56%"
            android:textColor="@color/colorPrimary"
            android:textStyle="bold"
            android:layout_below="@+id/from_test_date"
            android:id="@+id/from_time_year"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            />
        <View
            app:layout_marginLeftPercent="73%"
            app:layout_marginRightPercent="24%"
            android:id="@+id/divider"
            android:layout_width="match_parent"
            android:layout_height="4dp"
            android:background="@color/colorPrimaryDark"/>
        <TextView
            app:layout_marginLeftPercent="79.5%"
            app:layout_marginStartPercent="79.5%"
            android:textColor="@color/colorPrimary"
            android:textStyle="bold"
            app:layout_widthPercent="20%"
            android:id="@+id/to_test_date"
            android:layout_height="wrap_content"
            android:textSize="28sp"
            />
        <TextView
            app:layout_marginLeftPercent="77%"
            app:layout_marginStartPercent="77%"
            android:textColor="@color/colorPrimary"
            android:textStyle="bold"
            android:layout_below="@+id/to_test_date"
            app:layout_widthPercent="20%"
            android:id="@+id/to_time_year"
            android:layout_height="wrap_content"
            android:textSize="13sp"
            />
    </android.support.percent.PercentRelativeLayout>
</android.support.v7.widget.CardView>

,所以我认为为什么会发生这种情况有任何解释。但是我找到了一个工作,可能会帮助有人有类似问题的人。

因此,相对布局百分比可用于宽度。但是,您不能将其与保证金开始/左百分比或保证金端/右百分比一起进行搭配,其中(或全部4个)也可以一起工作。

因此,对于您必须以类似意义定义高度/边距的布局,您可以在百分位数中创建带有垂直取向的线性布局,指定其宽度倍数/边缘的速度/边缘,将高度设置为0dp并使用重量属性。线性布局中的元素。

i主要在卡视图中使用了它,而元素仅在屏幕的某个部分中使用,而不管屏幕尺寸或方向如何。

最新更新