如何添加水平滚动视图和Android的列表视图 [英] How to add horizontal scroll view and a listview in Android

查看:138
本文介绍了如何添加水平滚动视图和Android的列表视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图创建一个应用程序,我需要创建一个列表视图,但在那上面,我想对多个数据的列表视图水平。我很困惑,如何才能做到这一点。请帮我在这

I am trying to create a application in that i need to create a list view but on the top of that i want a horizontal listview for multiple data .I am confused how can we do this .please help me in this

MainActivityXML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
    android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    android:paddingBottom="@dimen/activity_vertical_margin"
    tools:context=".HomePage">

    <ScrollView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:id="@+id/mydata"
            android:orientation="vertical">
        </LinearLayout>

</ScrollView>

MYDATA 我要添加的动态XML的布局是:

In the mydata i want to add the dynamic xml layout that is :

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal" >
    <LinearLayout
        android:id="@+id/mainLinearLayout"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:orientation="horizontal" >
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@mipmap/ic_launcher"
            android:layout_marginTop="5dp"
            android:layout_marginLeft="10dp"/>

        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="10dp"
            android:layout_marginLeft="10dp"
            android:text="ABC DEF JKL"
            android:textColor="@android:color/black" />
    </LinearLayout>
</RelativeLayout>

而在 main_activity.xml 我想添加一个水平列表视图,但我没能做到这一点。

And in the main_activity.xml i want to add a horizontal listview but i am not able to do this .

Horizo​​ntialListView

<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:orientation="vertical"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:background="#fff"
  >

  <com.test.ui.HorizontialListView
    android:id="@+id/listview"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#ddd"
  />

</LinearLayout>

这是我的 horizo​​ntalitems

 <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="#fff"
    >

    <ImageView
        android:id="@+id/image"
        android:layout_width="150dip"
        android:layout_height="150dip"
        android:scaleType="centerCrop"
        android:src="@mipmap/ic_launcher"
        />

    <TextView
        android:id="@+id/title"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#000"
        android:gravity="center_horizontal"
        />

</LinearLayout>

我要创建这样的事情

I want to create something like this

Issuse我面临的是如何可以在连接所有的人。请指引我在这种

Issuse i am facing is how could the connect all them .Please guide me in this

推荐答案

您需要的是的 RecyclerView ,你可以有

What you need is RecyclerView, you can have

                <android.support.v7.widget.RecyclerView
                    android:id="@+id/recyclerView"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@color/white"
                    android:clipToPadding="false"/>

然后在code,可将横向这样的方向。

mRecyclerView = (RecyclerView) view.findViewById(R.id.recyclerView);
mRecyclerView.setHasFixedSize(true);
mLayoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.HORIZONTAL, false);
mRecyclerView.setLayoutManager(mLayoutManager);

您还可以使用 RecyclerView.Adapter 添加意见吧。所有设置:)

And you can use RecyclerView.Adapter for adding views to it. All set :)

这篇关于如何添加水平滚动视图和Android的列表视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆