Android studio 如何使mRecyclerView控件填充空闲空间?
我使用代码A设计带有约束布局的UI,UI的顶部是google广告,底部是工具栏 我希望名为mRecyclerView的RecyclerView控件填充所有其他空间,我该怎么办 顺便说一句,当我将RecyclerView控件拖放到UI时,代码B由Android Studio 3.01自动生成。这是布局宽度和布局高度的硬代码 代码AAndroid studio 如何使mRecyclerView控件填充空闲空间?,android-studio,Android Studio,我使用代码A设计带有约束布局的UI,UI的顶部是google广告,底部是工具栏 我希望名为mRecyclerView的RecyclerView控件填充所有其他空间,我该怎么办 顺便说一句,当我将RecyclerView控件拖放到UI时,代码B由Android Studio 3.01自动生成。这是布局宽度和布局高度的硬代码 代码A <?xml version="1.0" encoding="utf-8"?> <android.support.constraint.Constra
<?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">
<com.google.android.gms.ads.AdView xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="@+id/adView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
ads:layout_constraintTop_toTopOf="parent"
ads:adSize="SMART_BANNER"
ads:adUnitId="@string/ad_unit_id"
/>
<LinearLayout
android:id="@+id/linearLayoutToolBar"
style="@style/myToolbar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:weightSum="4"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">
<Button
android:id="@+id/btnBackup"
style="@style/myTextMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="@string/BtnBackup" />
<Button
android:id="@+id/btnExit"
style="@style/myTextMedium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:text="@string/BtnExit" />
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/mRecyclerView"
android:layout_width="368dp"
android:layout_height="396dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="58dp" />
</android.support.constraint.ConstraintLayout>
代码B
<android.support.v7.widget.RecyclerView
android:id="@+id/mRecyclerView"
android:layout_width="368dp"
android:layout_height="396dp"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="58dp" />
替换您的RecyclerView代码,如下所示,以填充可用空间:
<android.support.v7.widget.RecyclerView
android:id="@+id/mRecyclerView"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toBottomOf="@id/adView"
app:layout_constraintBottom_toTopOf="@id/linearLayoutToolBar"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"/>