开发者

How to scroll up the selected item

开发者 https://www.devze.com 2023-03-11 17:22 出处:网络
My application have Linear Layouts. how to scroll up the selected Linear Layout? it means suppose application have 5 linear layouts. if i selected 3rd Linear layout 开发者_开发问答then it will be top(

My application have Linear Layouts. how to scroll up the selected Linear Layout? it means suppose application have 5 linear layouts. if i selected 3rd Linear layout 开发者_开发问答then it will be top(means Starting) of the screen and at that time first 2 linear layouts are above the 3rd Linear Layout, 4th and 5th Linear Layouts are below the 3rd Linear layout.

How to do it?


Take a look at these ViewGroup methods:

public void removeViewAt (int index)  Since: API Level 1

public void addView (View child, int index)  Since: API Level 1

Having said that, you may want to consider using a ListView instead of a LinearLayout


Are you talking about not being able to see them in the editor? Or that you can't get to it on the handset?

If you can't see it in the xml editor viewer then you need to choose a larger simulated screen size so that it shows more of your app. That is only a temporary solution if you just want to see how things will look without compiling.

If you can't see the layouts on the handset, it is because they are taking up more vertical space than your handset has (obviously). The best way, in my opinion, to fix that is to add ScrollView to your main.xml. ScrollView can only have one child so what you want to do is put a LinearLayout within your ScrollView and put everything else in that as follows:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        >
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            >
                android:id="@+id/linearlayout1"
                ...
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >
                android:id="@+id/linearlayout2"
                ...
        </LinearLayout>
        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            >
                android:id="@+id/linearlayout3"
                ...
        </LinearLayout>
        ...
    </LinearLayout>
</ScrollView>
0

精彩评论

暂无评论...
验证码 换一张
取 消