Android水平滚动列表

发布于 2024-10-30 03:57:01 字数 457 浏览 1 评论 0原文

可能的重复:
Android 中的水平 ListView?

我想要像 Gallery 一样水平滚动。我不使用画廊,因为它的中心被锁定。

这里有人可以帮我解决这个问题吗?所以我可以有水平滚动列表?

我认为最好的例子是脉冲新闻阅读器:- https://market.android.com/details?id=com.alphonso。脉冲

谢谢:)

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 :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

梦毁影碎の 2024-11-06 03:57:01

http://developer.android.com/reference/android/widget/Horizo​​ntalScrollView。 html

编辑:好的,在发现我不需要做 RTFM 帖子后,我搜索了一下,之前已经有人问过这个问题:

Horizo​​ntal ListView在Android中?

并且已经在这里实现:

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

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

野却迷人 2024-11-06 03:57:01

我在 ScrollView 和 Horizo​​ntalScrollView 的帮助下创建了一个视图,至少可以给您一个开始。下面是该代码的 XML:

<?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>

加上 java 代码:

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 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!!

星星的軌跡 2024-11-06 03:57:01
 <HorizontalScrollView>
   ....Horizontal LinearLayout here....
</HorizontalScrollView>

在 Horizo​​ntal LinearLayout 中,您可以添加所有视图...

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

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

我为君王 2024-11-06 03:57:01
<HorizontalScrollView>
....your layout here....
</HorizontalScrollView>
<HorizontalScrollView>
....your layout here....
</HorizontalScrollView>
财迷小姐 2024-11-06 03:57:01

下载Pulse apk,使用dex2jar + JD-GUI反编译,看看他们是怎么做的!

摘录:

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

一位好心的先生/女士稍后可以用这个为我们大家写一个关于实现的教程吗? :-)

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? :-)

静待花开 2024-11-06 03:57:01

你不能改变图库中的android:gravity吗?

Cant you change the android:gravity in Gallery?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文