ConstraintLayout中的百分比和权重不起作用

时间:2019-04-23 14:27:16

标签: android android-linearlayout android-constraintlayout android-relativelayout

我正在RecyclerView中使用其他RecyclerView中的东西,而我正在weightpercent中使用,但下面却没有用,但是下面是主要布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorTextLight">

    <androidx.swiperefreshlayout.widget.SwipeRefreshLayout
        android:id="@+id/swpCourseContentFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <androidx.recyclerview.widget.RecyclerView
            android:id="@+id/courseContentRecycler"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    </androidx.swiperefreshlayout.widget.SwipeRefreshLayout>

    <ProgressBar
        android:id="@+id/courseContentFragmentProgress"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:visibility="gone" />

    <include
        android:id="@+id/courseContentFragmentInclude"
        layout="@layout/layout_empty_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_marginLeft="20dp"
        android:layout_marginRight="20dp"
        android:visibility="invisible" />

</RelativeLayout>

下面是布局项目:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/rltCourseContentListItem"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical"
    android:weightSum="3">

    <RelativeLayout
        android:id="@+id/rltTitleCourseContentListItem"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="0.3"
        android:background="@color/orangePeel">

        <TextView
            android:id="@+id/txtTitleCourseContentListItem"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center"
            android:textColor="@color/colorTextLight"
            android:textSize="15sp"
            android:textStyle="bold" />
    </RelativeLayout>

    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/rvSubItemCourseContentList"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="2.7"
        android:layout_gravity="right"
        android:divider="@null"
        android:dividerHeight="0dp" />
</LinearLayout>

下面的布局是下面的布局:

<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/constSubCourseContentList"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        app:layout_constraintHeight_percent="0.1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent">

        <View
            android:id="@+id/divider"
            android:layout_width="match_parent"
            android:layout_height="1dp"
            android:layout_margin="10dp"
            android:layout_marginTop="10dp"
            android:layout_marginBottom="10dp"
            android:background="@color/orangePeel"
            android:visibility="gone"
            app:layout_constraintBottom_toTopOf="@+id/txtMainNameContentCourseSubContentListItem"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <TextView
            android:id="@+id/txtMainNameContentCourseSubContentListItem"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:ellipsize="marquee"
            android:singleLine="true"
            android:textColor="@color/guardsman_red"
            android:visibility="gone"
            app:layout_constraintHorizontal_weight="2"
            app:layout_constraintLeft_toRightOf="@+id/imgDownload"
            app:layout_constraintRight_toRightOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <androidx.constraintlayout.widget.Guideline
            android:id="@+id/guideline"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.5"
            app:layout_constraintTop_toBottomOf="@+id/txtMainNameContentCourseSubContentListItem" />


        <TextView
            android:id="@+id/txtFileSizeCourseSubContentListItem"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="10dp"
            android:ellipsize="marquee"
            android:singleLine="true"
            android:textColor="@color/black"
            android:visibility="gone"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintHorizontal_weight="2"
            app:layout_constraintLeft_toRightOf="@+id/guideline"
            app:layout_constraintRight_toRightOf="parent" />

        <TextView
            android:id="@+id/txtExtensionCourseSubContentListItem"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:ellipsize="marquee"
            android:singleLine="true"
            android:textColor="@color/black"
            android:visibility="gone"
            app:layout_constraintBaseline_toBaselineOf="@+id/txtFileSizeCourseSubContentListItem"
            app:layout_constraintHorizontal_weight="2"
            app:layout_constraintLeft_toRightOf="@+id/imgDownload"
            app:layout_constraintRight_toLeftOf="@id/guideline" />

        <ImageButton
            android:id="@+id/imgDownload"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@null"
            android:padding="10dp"
            android:visibility="gone"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintLeft_toLeftOf="parent"
            app:layout_constraintTop_toTopOf="parent"
            app:srcCompat="@drawable/ic_downloader" />
    </androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

0 个答案:

没有答案