gpt4 book ai didi

Android ScrollView fillViewport 不工作

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:43:09 27 4
gpt4 key购买 nike

我有一个简单的布局,顶部有一个名称,还有一个按钮,我希望它位于屏幕底部,或者超出它以防我添加更多项目。

所以我使用 ScrollView 和 LinearLayout 如下:

<ScrollView 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:background="@android:color/white"
android:fillViewport="true"
android:focusableInTouchMode="true"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
tools:context=".ItemDetailActivity" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >

<!-- Name -->

<RelativeLayout
android:id="@+id/top_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="top" >

<TextView
android:id="@+id/name_label"
style="@style/Header_Label_TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/name" />

<TextView
android:id="@+id/name_value"
style="@style/Value_Label_TextView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/name_label" />
</RelativeLayout>

<!-- button -->

<RelativeLayout
android:id="@+id/ButtonLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom" >

<Button
android:id="@+id/add_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:onClick="editItem"
android:text="@string/button_edit" />
</RelativeLayout>

<requestFocus />
</LinearLayout>

这是我得到的:

Result of the layout XML

如何使按钮出现在屏幕底部或更远的地方。在网上搜索后,大多数答案都是设置 `android:fillViewport="true",但这并没有帮助。我做错了什么?

最佳答案

像这样改变你的按钮布局:

 <RelativeLayout
android:id="@+id/ButtonLayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom" >

<Button
android:id="@+id/add_button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10sp"
android:onClick="editItem"
android:layout_alignParentBottom="true"
android:text="@string/button_edit" />
</RelativeLayout>

关于Android ScrollView fillViewport 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18780619/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com