当ScrollView作为父布局时ScrollView不滚动
问题描述:
我在ScrollView中有一个RelativeLayout。但是,当它作为父布局时,ScrollView不会滚动。当ScrollView作为父布局时ScrollView不滚动
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv_about_background"
android:layout_width="match_parent"
android:layout_height="150dp"
android:src="@drawable/stack" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_about_background"
android:paddingLeft="10dp"
android:paddingRight="10dp"
/>
</RelativeLayout>
</ScrollView>
编辑:我取下rootView.setOnTouchListener
从我的片段和ScrollView
工作正常
答
尝试
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:orientation="vertical"
android:fillViewport="false"
android:layout_height="match_parent"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/iv_about_background"
android:layout_width="match_parent"
android:layout_height="150dp"
android:src="@drawable/stack" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_about_background"
android:paddingLeft="10dp"
android:paddingRight="10dp"
/>
</RelativeLayout>
</LinearLayout>
</ScrollView>
答
有几件事情,你可以做:
确保相对于布局高度内容不仅仅是父母。我认为150dp和10dp仍然低于父母身高。
将ScrollView的宽度和高度更改为
fill_parent
而不是match_parent
,并对相对布局执行相同的操作。添加
android:scrollbars = "vertical"
财产,滚动型
希望它是有益的。
+0
我试过用TextView上的大文本,它不滚动 – Ameer
答
试试这个,希望它会帮助你。
<?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:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/iv_about_background"
android:layout_width="match_parent"
android:layout_height="150dp"
android:src="@drawable/stack" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_about_background"
android:paddingLeft="10dp"
android:paddingRight="10dp" />
</RelativeLayout>
</LinearLayout>
答
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:fillViewport="true"
android:layout_height="match_parent"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/iv_about_background"
android:layout_width="match_parent"
android:layout_height="350dp"
android:src="@drawable/stack" />
<TextView
android:text="rgergijsojsoierjgoegorijtowjtojrtoihjorjthlbkmoijbrotoojgowijtogirtjhowortgjowjtgjwrtgjowrijgtoiwjt"
android:textSize="50sp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/iv_about_background"
android:paddingLeft="10dp"
android:paddingRight="10dp"
/>
</RelativeLayout>
我已经改变了图像的高度,大小350dp并设置文字大小50SP知道代码是否你已经发布的作品或没有。你的代码非常好,但是你必须在scrollview中添加更多的视图,或者增加textview的图像/字体大小的大小(如上面的代码所示)。
你的滚动视图结束在哪里? –
https://*.com/questions/20896963/relativelayout-inside-scrollview-not-working –
@ Harshit Trivedi错过了复制时的行。问题更新 – Ameer