gpt4 book ai didi

android - 在 ScrollView 中居中内容

转载 作者:IT老高 更新时间:2023-10-28 23:37:19 24 4
gpt4 key购买 nike

我想在 ScrollView 中将我的 LinearLayout 居中。当 LinearLayout 的高度很小时,它可以居中(见图 #1),但是当 LinearLayout 的高度大于屏幕的高度时,它的行为就会很奇怪。我看不到 LinearLayout 的顶部(见图 #2),并且在 ScrollView 的底部有巨大的填充。我不知道这里发生了什么。当 LinearLayout 中有很多内容时,整个屏幕应该看起来像图片 #3。

image #1
image #2
image #3

这是我的布局文件:

            <?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#cccfff" >

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_margin="28dp"
android:background="#ffffff"
android:orientation="vertical"
android:paddingBottom="40dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="40dp" >

<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="16dp"
android:src="@drawable/ic_launcher" />

<TextView
android:id="@+id/tip_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:text="Title"
android:textColor="@color/orange_text"
android:textSize="@dimen/font_size_medium" />

<TextView
android:id="@+id/tip_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Description description..."
android:textSize="@dimen/font_size_small" />
</LinearLayout>

</ScrollView>

最佳答案

您可以使用 android:fillViewport="true" 使内容居中。像这样的:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<!-- content -->
</ScrollView>

关于android - 在 ScrollView 中居中内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19540310/

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