开发者

Android horizontal scroll list [duplicate]

This question already has answers here开发者_Python百科: Closed 10 years ago.

Possible Duplicate:

Horizontal ListView in Android?

I want horizontal scroll like Gallery. Im not using Gallery because its center locked.

Can some one here would help me out with this So I can have horizontal scrolling list?

I think best example of this is pulse news reader :- https://market.android.com/details?id=com.alphonso.pulse

Thanks :)


http://developer.android.com/reference/android/widget/HorizontalScrollView.html ?

EDIT: Ok after finding out i don't need to do a RTFM post i searched around a bit and this has been asked before here:

Horizontal ListView in Android?

And has already been implemented here:

http://dev-smart.com/?p=34


I have created a view with the help of ScrollView and HorizontalScrollView to give you atleast a start. Here is the XML of that code:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="wrap_content">
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="fill_parent"
        android:layout_height="wrap_content" android:padding="5dp">

        <HorizontalScrollView android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <LinearLayout android:id="@+id/a" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:padding="5dp"
                android:layout_weight="1">
            </LinearLayout>
        </HorizontalScrollView>

        <HorizontalScrollView android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <LinearLayout android:id="@+id/b" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:padding="5dp"
                android:layout_weight="1">
            </LinearLayout>
        </HorizontalScrollView>

        <HorizontalScrollView android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <LinearLayout android:id="@+id/c" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:padding="5dp"
                android:layout_weight="1">
            </LinearLayout>
        </HorizontalScrollView>

        <HorizontalScrollView android:layout_width="fill_parent"
            android:layout_height="fill_parent">
            <LinearLayout android:id="@+id/d" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:padding="5dp"
                android:layout_weight="1">
            </LinearLayout>
        </HorizontalScrollView>

    </LinearLayout>
</ScrollView>

Plus java code:

public class SampleActivity extends Activity {

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        LinearLayout linearLayout = (LinearLayout) findViewById(R.id.a);
        LinearLayout linearLayout1 = (LinearLayout) findViewById(R.id.b);
        LinearLayout linearLayout2 = (LinearLayout) findViewById(R.id.c);
        LinearLayout linearLayout3 = (LinearLayout) findViewById(R.id.d);

        for (int i = 0; i < 10; i++) {

            ImageView imageView = new ImageView(this);
            imageView.setImageResource(R.drawable.sample_0);
            linearLayout.addView(imageView);

            ImageView imageView1 = new ImageView(this);
            imageView1.setImageResource(R.drawable.sample_1);
            linearLayout1.addView(imageView1);

            ImageView imageView2 = new ImageView(this);
            imageView2.setImageResource(R.drawable.sample_2);
            linearLayout2.addView(imageView2);

            ImageView imageView3 = new ImageView(this);
            imageView3.setImageResource(R.drawable.sample_3);
            linearLayout3.addView(imageView3);
        }
    }

}

I tried uploading some screenshots also but i guess it was blocked by my network firewall. so will upload them later.

Hope this helps!!


 <HorizontalScrollView>
   ....Horizontal LinearLayout here....
</HorizontalScrollView>

Inside the Horizontal LinearLayout you can add all your views...


<HorizontalScrollView>
....your layout here....
</HorizontalScrollView>


Download Pulse apk, decompile using dex2jar + JD-GUI and take a look how they do it!

Excerpt:

package com.alphonso.pulse.views;

import android.content.Context;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.widget.Gallery;

public class HorizontalTileView extends Gallery
{
... etc

Can a kind gentleman/lady later use this to write us all a tutorial on the implementation? :-)


Cant you change the android:gravity in Gallery?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜