我在app:layout_constraintVertical_weight="5"
使用ConstraintLayout
,但它无效。
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtComingSoon"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#E1E2E4"
android:text="New Courses Starting Soon.."
android:textColor="#747577"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_weight="5"
android:layout_marginTop="0dp" />
<android.support.constraint.ConstraintLayout
android:id="@+id/constImageButtons"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#FF9F00"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintVertical_weight="5"
android:layout_marginBottom="0dp">
<ImageButton
android:id="@+id/imbRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/ic_register"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imbMedia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/ic_media"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/imbRegister"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imbWebinar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/ic_webinar"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/imbMedia"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imbAboutUs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/ic_about_us"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/imbWebinar"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imbNews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitXY"
android:src="@drawable/ic_news"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/imbAboutUs"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerMouFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/constImageButtons"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtComingSoon"
app:layout_constraintVertical_bias="0.0"
app:layout_constraintVertical_weight="8" />
</android.support.constraint.ConstraintLayout>
我需要这个:
我是ConstraintLayout
的初学者,我需要使用ConstraintLayout
,weight
LinearLayout
。
答案 0 :(得分:1)
尝试以下:
<android.support.constraint.ConstraintLayout
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:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/txtComingSoon"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#E1E2E4"
android:text="New Courses Starting Soon.."
android:textColor="#747577"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toTopOf="@+id/recyclerMouFragment"
app:layout_constraintVertical_weight="1"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerMouFragment"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toTopOf="@+id/constImageButtons"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toBottomOf="@+id/txtComingSoon"
app:layout_constraintVertical_weight="8" />
<android.support.constraint.ConstraintLayout
android:id="@+id/constImageButtons"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#FF9F00"
app:layout_constraintTop_toBottomOf="@+id/recyclerMouFragment"
app:layout_constraintVertical_weight="1"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintHorizontal_chainStyle="packed"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<ImageButton
android:id="@+id/imbRegister"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imbMedia"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/imbRegister"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imbWebinar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/imbMedia"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imbAboutUs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/imbWebinar"
app:layout_constraintTop_toTopOf="parent" />
<ImageButton
android:id="@+id/imbNews"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:background="@null"
android:scaleType="fitXY"
android:src="@mipmap/ic_launcher"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toRightOf="@+id/imbAboutUs"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>