包装内容不起作用,滚动停止工作。
您好,我正在为 Android 开发一个应用程序,我注意到我的应用程序在智能手机上运行良好,但是在纵向模式下的平板电脑上它增加了巨大的空间并且 ScrollView 停止工作。
智能手机的 View :
平板电脑的 View :
我的 XML 代码:
<?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:fillViewport="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:paddingRight="10dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/descAbout"
android:layout_marginBottom="10dp"
android:textSize="16sp"
android:layout_marginTop="10dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_marginBottom="10dp"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true">
<ImageView
android:id="@+id/imgSpaceApps"
android:layout_width="wrap_content"
android:layout_height="115dp"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:src="@drawable/spaceApps" />
<ImageView
android:id="@+id/imgNasaLogo"
android:layout_width="wrap_content"
android:layout_height="115dp"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:src="@drawable/nasaLogo" />
</LinearLayout>
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="@string/lblContact2"
android:layout_marginBottom="5dp" />
<TextView
android:id="@+id/lblOurEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="@string/lblContactUs"
android:clickable="true"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="@string/lblVisit"
android:autoLink="web"
android:layout_marginBottom="5dp" />
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="@string/lblSpecialGreeting"
android:layout_marginBottom="5dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:autoLink="web"
android:text="@string/url7"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:autoLink="web"
android:text="@string/url8"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:autoLink="web"
android:text="@string/url6"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:autoLink="web"
android:text="@string/url5"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:autoLink="web"
android:text="@string/url1"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:autoLink="web"
android:text="@string/url2"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:autoLink="web"
android:text="@string/url3"
android:layout_marginBottom="10dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:autoLink="web"
android:text="@string/url4"
android:layout_marginBottom="10dp" />
<TextView
android:textStyle="bold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:text="@string/lblPPrivacy"
android:layout_marginBottom="5dp" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="16sp"
android:autoLink="web"
android:text="@string/url9"
android:layout_marginBottom="10dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_marginBottom="5dp"
android:adjustViewBounds="true"
android:layout_gravity="center"
android:src="@drawable/supernova" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textSize="14sp"
android:text="@string/About6"
android:layout_marginBottom="10dp" />
</LinearLayout>
</ScrollView>
如果我删除以下属性:
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"
结果是一样的:
我正在 Android 6 和 7 中测试,另外,最低 SDK 是 21。
有没有人遇到过这种情况?感谢您的帮助。
最佳答案
正如我在评论中提到的,原因是保存图像的 RelativeLayout。 当与“wrap_content”一起使用时,RelativeLayout 可能会导致意外结果,它实际上会尝试匹配其父项并将子项布置在边缘。
在这种情况下,RelativeLayout 无论如何都没什么用;您可以删除它并稍微更改子 LinearLayout 的属性:
...
<LinearLayout
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:gravity="center_horizontal"
>
<ImageView
android:id="@+id/imgSpaceApps"
android:layout_width="wrap_content"
android:layout_height="115dp"
android:adjustViewBounds="true"
android:src="@drawable/spaceApps" />
<ImageView
android:id="@+id/imgNasaLogo"
android:layout_width="wrap_content"
android:layout_height="115dp"
android:adjustViewBounds="true"
android:src="@drawable/nasaLogo" />
</LinearLayout>
...
关于android - 包装内容不起作用并且滚动停止工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48950575/