安卓ScrollView无法工作

3

我创建了一些XML活动文件。我编写了一些代码。我使用scrollview,但是这个scrollview不起作用。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fillViewport="true"
android:background="#171717" >

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <RelativeLayout
        android:id="@+id/relativeLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_marginBottom="22dp"
        android:background="#171717" >

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginBottom="15dp"
            android:layout_marginRight="15dp"
            android:background="@drawable/ic_launcher" />

        <EditText
            android:id="@+id/editText1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignBottom="@+id/imageView1"
            android:layout_alignParentLeft="true"
            android:layout_alignTop="@+id/imageView1"
            android:layout_marginLeft="15dp"
            android:layout_marginRight="5dp"
            android:layout_toLeftOf="@+id/imageView1"
            android:background="#363636"
            android:paddingLeft="10dp"
            android:textColor="#ffffff" >
        </EditText>
    </RelativeLayout>

    <TextView
        android:id="@+id/latteryresult"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/circlelayout2"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="28dp"
        android:gravity="center"
        android:text="click the button"
        android:textColor="#ffffff"
        android:textSize="17dp" />

    <RelativeLayout
        android:id="@+id/circlelayout2"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_centerHorizontal="true"
        android:layout_marginBottom="14dp"
        android:layout_marginTop="15dp" >


    </RelativeLayout>
  </RelativeLayout>

</ScrollView>

当我点击编辑文本并弹出键盘时,我无法滚动,滚动视图不起作用。我做错了什么?如果有人知道解决方法,请帮忙。

您的布局中没有 ScrollView。 - atok
@atok scrollview 是根视图。 - tyczj
你在清单文件中设置了android:windowSoftInputMode吗?它应该可以使用默认值,但如果设置为“adjustPan”,则无法正常工作。 - atok
@atok 不,先生,我没有。 - chromelend
布局宽度设置为“wrap_content”的原因是什么?“match_parent”将是一个正常的值。 - atok
@atok width 可以设为 wrap_content,这应该不会有问题。 - codeMagic
1个回答

0

你的第一个 RelativeLayout 必须将 android:layout_height 设置为 wrap_content

因为 match_parent 不允许视图扩展超过(可见)ScrollView 的高度。


如果我使用"wrapcontent",滚动是管用的,但是我的内容会上移。重量不起作用,底部重力也不起作用。 - m.v.n.kalyani
任何其他解决方案都需要滚动整个屏幕才能将内容放在屏幕底部。 - m.v.n.kalyani
@m.v.n.kalyani,您能否画一个小插图,说明您想要的具体效果?因为在可滚动的内容中使用 android:layout_alignParentBottom="true" 不是很恰当。 - Kevin Robatel
我想要在屏幕底部的scrollview中显示内容。 - m.v.n.kalyani
好的,但如果你将内容放在底部,那么内容就少于scrollview的高度了。为什么要添加scrollview呢?很抱歉,也许一个显示将会被滚动的指示屏幕是一个好的理解方式。我相信我们可以找到解决方案! :) - Kevin Robatel
你需要在ScrollView上使用android:fillViewport标志,然后内容应该是 wrap_contentlayout_gravity="bottom" - RadekJ

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接