Nag*_*ori 4 android android-constraintlayout
这是我使用的代码ConstraintLayout
<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"
tools:context="com.lokeshlabs.filterableexample.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_movie"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
这是布局项
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/listPreferredItemHeight"
android:layout_margin="4dp"
android:weightSum="100"
android:orientation="horizontal">
<TextView
android:id="@+id/tv_movie_name"
android:layout_width="0dp"
android:layout_weight="80"
android:layout_height="match_parent"
android:hint="movie name"
android:textColor="@android:color/black"
android:textSize="22sp" />
<TextView
android:id="@+id/tv_year"
android:layout_width="0dp"
android:layout_weight="20"
android:layout_height="match_parent"
android:hint="year"
android:padding="8dp"
android:gravity="end"
android:textColor="@android:color/black"
android:textSize="18sp"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我得到的输出
当我将其更改为Linear layout或relative layout工作正常时
使用线性布局代码
<?xml version="1.0" encoding="utf-8"?>
<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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.lokeshlabs.filterableexample.MainActivity">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_movie"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这是我使用上面代码时的输出
甚至尝试了里面的所有方法constraintlayout,但没有用,可能是一个错误
如果您要在constraintlayout.
请注意,“MATCH_PARENT不建议对 中包含的小部件使用此方法ConstraintLayout。可以通过将MATCH_CONSTRAINT相应的左/右或顶部/底部约束设置为父级来定义类似的行为”(在开发人员站点的文档中)。
试试这个布局。这应该对你有帮助。
<?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"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_movie"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)