繁体   English   中英

如何滚动滚动视图以在Android顶部显示子视图

[英]How to scroll a scrollview to come a subview in top in Android

我在活动视图中有一个滚动视图,在此布局中,我将通过在循环中使另一个布局膨胀来增加动态内容(在“ ucontent”,“ pcontent”中)(膨胀的布局数量随时间而变化)。我需要滚动scrollview sv,以便当我单击“ titlep”时,带有“ titlep”的翻盖出现在顶部。

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/sv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#232323"
android:scrollbars="none" >

<LinearLayout
    android:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:background="#232323"
    android:orientation="vertical" >

    <LinearLayout
        android:id="@+id/titleu"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#D84A49"
        android:orientation="horizontal"
        android:paddingBottom="7dp"
        android:paddingTop="7dp" >

        <ImageView
            android:id="@+id/toggleu"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="2dp"
            android:src="@drawable/toggleu" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:text="title1....."
            android:textColor="#ffffff" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/ucontent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    </LinearLayout>

    <LinearLayout
        android:id="@+id/titlep"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:layout_marginBottom="0dp"
        android:layout_marginTop="5dp"
        android:background="#D84A49"
        android:orientation="horizontal"
        android:paddingBottom="7dp"
        android:paddingTop="7dp" >

        <ImageView
            android:id="@+id/togglep"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginLeft="2dp"
            android:src="@drawable/toggleu" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="10dp"
            android:layout_weight=".1"
            android:text="title2...."
            android:textColor="#ffffff" />
    </LinearLayout>

    <LinearLayout
        android:id="@+id/pcontent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical" >
    </LinearLayout>
</LinearLayout>

如何在我的代码或xml中做到这一点?

看看这个:

观看次数

使用isFocusable(true)

并在onClick上使用requestFocus()

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM