ScrollView 被底部按钮栏截断
ScrollView being cutoff by bottom button bar
我在这里看到了很多关于这个问题的答案,但是 none 确实对我有用(唯一的例外是底部填充,我认为这是一个丑陋的解决方法)。
我在 Fragment 中的 LinearLayout 中有一个 ScrollView。无法看到内容的最后一行(或左右),因为它隐藏在按钮后面。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="domain.idiotic.no.majlen.jidelnicek.MainActivity$PlaceholderFragment"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/section_label"
android:layout_weight="0"
android:layout_gravity="center_horizontal" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/scrollView"
android:layout_weight="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listLayout">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView"
android:width="0px"
android:layout_weight="0.8" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView2"
android:width="0px"
android:layout_weight="0.2" />
</TableRow>
</LinearLayout>
</ScrollView>
</LinearLayout>
如果我删除 "Medium text" TextView,这个问题仍然存在,所以这不是导致它的视图。我已经尝试设置不同的 layout_heights 和 layout_weights 所有应该拉伸的视图,但到目前为止我没有运气。
Demonstration of the issue described, all the items are supposed to be doubled
在 ScrollView
上设置 android:fillViewport="true"
使用它并检查。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="domain.idiotic.no.majlen.jidelnicek.MainActivity$PlaceholderFragment"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/section_label"
android:layout_weight="0"
android:layout_gravity="center_horizontal" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/scrollView"
android:layout_weight="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listLayout">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView"
android:layout_weight="0.5" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView2"
android:layout_weight="0.5" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
希望对你有所帮助
尽管不完美,但对我有用的解决方案是将此代码添加到 Fragment
的 onCreateView()
方法中:
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
density = Math.ceil(getResources().getDisplayMetrics().density);
realStatusBarHeight = (int) Math.ceil(statusBarHeight * density);
}
ScrollView scroll = (ScrollView) rootView.findViewById(R.id.scrollView);
scroll.setPadding(scroll.getPaddingLeft(), scroll.getPaddingTop(), scroll.getPaddingRight(), scroll.getPaddingBottom() + realStatusBarHeight);
感谢@Gi0rgi0s 为我指出状态栏高度的方向。
我在这里看到了很多关于这个问题的答案,但是 none 确实对我有用(唯一的例外是底部填充,我认为这是一个丑陋的解决方法)。
我在 Fragment 中的 LinearLayout 中有一个 ScrollView。无法看到内容的最后一行(或左右),因为它隐藏在按钮后面。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="domain.idiotic.no.majlen.jidelnicek.MainActivity$PlaceholderFragment"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/section_label"
android:layout_weight="0"
android:layout_gravity="center_horizontal" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/scrollView"
android:layout_weight="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listLayout">
<TableRow
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView"
android:width="0px"
android:layout_weight="0.8" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView2"
android:width="0px"
android:layout_weight="0.2" />
</TableRow>
</LinearLayout>
</ScrollView>
</LinearLayout>
如果我删除 "Medium text" TextView,这个问题仍然存在,所以这不是导致它的视图。我已经尝试设置不同的 layout_heights 和 layout_weights 所有应该拉伸的视图,但到目前为止我没有运气。
Demonstration of the issue described, all the items are supposed to be doubled
在 ScrollView
上设置 android:fillViewport="true"使用它并检查。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="domain.idiotic.no.majlen.jidelnicek.MainActivity$PlaceholderFragment"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/section_label"
android:layout_weight="0"
android:layout_gravity="center_horizontal" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:id="@+id/scrollView"
android:layout_weight="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/listLayout">
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView"
android:layout_weight="0.5" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="New Text"
android:id="@+id/textView2"
android:layout_weight="0.5" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
希望对你有所帮助
尽管不完美,但对我有用的解决方案是将此代码添加到 Fragment
的 onCreateView()
方法中:
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
density = Math.ceil(getResources().getDisplayMetrics().density);
realStatusBarHeight = (int) Math.ceil(statusBarHeight * density);
}
ScrollView scroll = (ScrollView) rootView.findViewById(R.id.scrollView);
scroll.setPadding(scroll.getPaddingLeft(), scroll.getPaddingTop(), scroll.getPaddingRight(), scroll.getPaddingBottom() + realStatusBarHeight);
感谢@Gi0rgi0s 为我指出状态栏高度的方向。