【问题标题】:ScrollView being cutoff by bottom button barScrollView 被底部按钮栏截断
【发布时间】:2016-03-28 03:34:36
【问题描述】:

我在这里看到了很多关于这个问题的答案,但没有一个真的对我有用(唯一的例外是底部填充,我认为这是一个丑陋的解决方法)。

我在 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>

如果我删除“中文本”TextView,这个问题仍然存在,所以这不是导致它的视图。我尝试为所有应该拉伸的视图设置不同的 layout_heights 和 layout_weights,但到目前为止我还没有运气。

Demonstration of the issue described, all the items are supposed to be doubled

【问题讨论】:

  • 嗯,什么Buttons?为什么你有一个TableRow 而没有TableLayout
  • 我指的是安卓软按钮。 TableLayout 没有改变任何东西。
  • 如果您担心底部填充使用常量,您可以像这样以编程方式设置底部填充:stackoverflow.com/questions/8689117/…

标签: android android-fragments scrollview


【解决方案1】:

在 ScrollView 上设置 android:fillViewport="true"

【讨论】:

  • 什么都没有改变。
【解决方案2】:

使用它并检查。

<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>

希望对你有帮助。

【讨论】:

  • 不幸的是,它的行为仍然相同。无法看到最后一项。我想知道我是不是做错了什么……
  • @Majlen 我更改了代码,检查一下。如果您再次遇到问题,请提供更多详细信息或通过图片显示。
  • 我在原帖中添加了一个例子。 LinearLayout 以编程方式填充。现在我创建了一个使用 LinearLayout 而不是 TableRow 的静态示例,就像您的代码中那样,其中 Last 2 TextViews 包含不同的消息,因此可以看到。如图所示,问题仍然存在:home.zcu.cz/~majlen/issue.png
  • 您是否尝试在该标题和列表视图之间创建边距?
【解决方案3】:

虽然不完美,但对我有用的解决方案是将此代码添加到 FragmentonCreateView() 方法中:

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 为我指出状态栏高度的方向。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多