Android 边距和填充不适用于 ScrollView 内的 RecyclerView
Android Margin and Padding aren't working for RecyclerViews inside ScrollViews
当我将 RecyclerView 作为 ScrollView 的子级放置时,marginBottom
和 paddingBottom
不起作用。为父 LinearLayout
设置这些值也不会影响任何事情。 ScrollView
似乎没有滚动到底部,因为 ScrollBar
没有到达底部。我该如何修复这个错误?
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<!--To avoid scroll view from scrolling to the bottom automatically-->
<View android:layout_width="match_parent" android:id="@+id/focus_view" android:layout_height="0dp" android:focusable="true" android:focusableInTouchMode="true"><requestFocus/></View>
<ScrollView
android:id="@+id/sv_categories_statistics"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="4dp">
<LinearLayout
android:id="@+id/ll_categories_statistics_filters_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp">
<LinearLayout
android:id="@+id/ll_categories_statistics_select_date_fragment_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/border_primary_light"
android:padding="4dp"
android:layout_marginEnd="4dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/border_accent"
android:padding="4dp">
<Spinner
android:id="@+id/spn_categories_statistics_bill_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/pc_categories_statistics"
android:layout_width="match_parent"
android:layout_height="325dp"
android:layout_margin="4dp"/>
<fragment
android:id="@+id/fgm_categories_statistics_not_enough_data"
class="com.dolinsek.elias.cashcockpit.NotEnoughDataFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
app:text="@string/label_not_enough_data_for_statistic"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="8dp"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_categories_statistics"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
你试过了吗clipToPadding
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_categories_statistics"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="50dp"
android:clipToPadding="false"/>
当我将 RecyclerView 作为 ScrollView 的子级放置时,marginBottom
和 paddingBottom
不起作用。为父 LinearLayout
设置这些值也不会影响任何事情。 ScrollView
似乎没有滚动到底部,因为 ScrollBar
没有到达底部。我该如何修复这个错误?
<LinearLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<!--To avoid scroll view from scrolling to the bottom automatically-->
<View android:layout_width="match_parent" android:id="@+id/focus_view" android:layout_height="0dp" android:focusable="true" android:focusableInTouchMode="true"><requestFocus/></View>
<ScrollView
android:id="@+id/sv_categories_statistics"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="10">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_margin="4dp">
<LinearLayout
android:id="@+id/ll_categories_statistics_filters_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="4dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="4dp">
<LinearLayout
android:id="@+id/ll_categories_statistics_select_date_fragment_container"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/border_primary_light"
android:padding="4dp"
android:layout_marginEnd="4dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@drawable/border_accent"
android:padding="4dp">
<Spinner
android:id="@+id/spn_categories_statistics_bill_type"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
</LinearLayout>
<com.github.mikephil.charting.charts.PieChart
android:id="@+id/pc_categories_statistics"
android:layout_width="match_parent"
android:layout_height="325dp"
android:layout_margin="4dp"/>
<fragment
android:id="@+id/fgm_categories_statistics_not_enough_data"
class="com.dolinsek.elias.cashcockpit.NotEnoughDataFragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="24dp"
app:text="@string/label_not_enough_data_for_statistic"
android:layout_marginStart="4dp"
android:layout_marginEnd="4dp"
android:layout_marginBottom="8dp"/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_categories_statistics"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</LinearLayout>
</ScrollView>
你试过了吗clipToPadding
<android.support.v7.widget.RecyclerView
android:id="@+id/rv_categories_statistics"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="50dp"
android:clipToPadding="false"/>