Android水平滚动列表

Android水平滚动列表,android,listview,gallery,horizontallist,Android,Listview,Gallery,Horizontallist,可能重复: 我想要水平卷轴一样的画廊。我没有使用Gallery,因为它的中心已锁定 这里有人能帮我吗?这样我就可以有水平滚动列表了 我认为最好的例子是pulse news reader:- 谢谢:) …你的布局在这里。。。。 编辑:确定在发现我不需要做RTFM文章后,我四处搜索了一下,在这里之前有人问过这个问题: 并已在这里实施: 你能在Gallery中更改android:gravity吗?我在ScrollView和HorizontalScrollView的帮助下创建了一个视图,让你至少

可能重复:

我想要水平卷轴一样的画廊。我没有使用Gallery,因为它的中心已锁定

这里有人能帮我吗?这样我就可以有水平滚动列表了

我认为最好的例子是pulse news reader:-

谢谢:)


…你的布局在这里。。。。

编辑:确定在发现我不需要做RTFM文章后,我四处搜索了一下,在这里之前有人问过这个问题:

并已在这里实施:


你能在Gallery中更改android:gravity吗?

我在ScrollView和HorizontalScrollView的帮助下创建了一个视图,让你至少有一个开始。以下是该代码的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);
        }
    }

}
public类SampleActivity扩展活动{
创建时的公共void(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 LinearLayout 3=(LinearLayout)findViewById(R.id.d);
对于(int i=0;i<10;i++){
ImageView ImageView=新的ImageView(此);
setImageResource(R.drawable.sample_0);
linearLayout.addView(图像视图);
ImageView imageView1=新的ImageView(此);
imageView1.setImageResource(R.drawable.sample_1);
linearLayout1.addView(图像视图1);
ImageView imageView2=新的ImageView(此);
imageView2.setImageResource(R.drawable.sample_2);
linearLayout2.addView(图像视图2);
ImageView imageView3=新的ImageView(此);
imageView3.setImageResource(R.drawable.sample_3);
linearLayout3.addView(图像视图3);
}
}
}
我也试着上传一些截图,但我猜它被我的网络防火墙屏蔽了。所以我稍后会上传

希望这有帮助


 <HorizontalScrollView>
   ....Horizontal LinearLayout here....
</HorizontalScrollView>
……此处的水平线布局。。。。

在水平线性布局中,您可以添加所有视图…

下载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

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

HorizontalScrollView只能包含一个子视图。我想要很多孩子的,例如画廊可以有很多孩子的,垂直列表视图也可以有很多孩子的。我想要同样的方式,但水平而不是垂直。谢谢你的礼物。我已经实现了水平列表作为我的UI库的一部分。代码非常简洁。您可以在这里@snapix找到它。您能否提供一种方法将您的库导入到
Android Studio
?您好,因为库没有定期维护。我建议您将感兴趣的源文件复制到项目中。您将能够修改和自定义它们。HorizontalScrollView只能包含一个子视图。我想要很多孩子的,例如画廊可以有很多孩子的,垂直列表视图也可以有很多孩子的。我想要同样的方式,但水平而不是垂直。谢谢简单地在中放置一个,然后将子项添加到库中的选定项始终处于中心锁定状态。如果单击左侧项目,则它会将其置于中间。我不想要那种功能。所选项目应留在那里并被选中。不使用GalleryBuddy的原因也是如此,它应该是Gallery或ListView之类的东西,即我可以设置适配器。适配器重用视图。如果我在LinearLayout中插入所有视图,那么如果列表变长,它会使应用程序变慢,因为我有图像和文本作为项目。哦,好吧,如果Android不提供视图,我想你必须自己编写:)是的,我想如果有人这样做了,我可以直接实现它,而不是重新发明轮子,我对Android非常陌生,所以不知道我会怎么做。ThanksGallery的选定项目始终处于中心锁定状态。如果单击左侧项目,则它会将其置于中间。我不想要那种功能。所选项目应留在那里并被选中。不使用Gallery的原因也是我的答案。对不起,第一个答案是。。我没有正确地阅读你的问题(感谢mudit的努力。我们可以使用Gallery或ListView之类的工具吗,即我可以设置适配器。适配器重用该视图。如果我在LinearLayout中插入所有视图,那么如果列表变长,它会使应用程序变慢,或者有时会崩溃,因为我将图像和文本作为项目。对于仅包含文本的短列表,您的代码可以。我想,现在您必须e一些你想写什么就写什么的努力,这只是一个如何开始的想法。:PSeems这是一个非常常见的问题,看看我发现了什么:哪些指向实现了水平滚动列表视图的人,也许你至少可以作为一个起点:添加一些与代码相关的信息,否则这篇文章就没什么帮助了
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