Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/219.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 从ListView在视图中显示一行_Android_Listview - Fatal编程技术网

Android 从ListView在视图中显示一行

Android 从ListView在视图中显示一行,android,listview,Android,Listview,我以编程方式创建了一个ListView,我只需要在红色边框之间显示一行而不是多个项目,然后滚动以获取其他项目 这是我的职责 public void fillFormules(List<Category> objectsTextToShow) { LinearLayout layoutItemDetail = (LinearLayout) view.findViewById(R.id.middle); LinearLayout relativeLayout

我以编程方式创建了一个ListView,我只需要在红色边框之间显示一行而不是多个项目,然后滚动以获取其他项目

这是我的职责

    public void fillFormules(List<Category> objectsTextToShow)

{
    LinearLayout layoutItemDetail = (LinearLayout) view.findViewById(R.id.middle);
    LinearLayout relativeLayout = (LinearLayout) view.findViewById(R.id.titles);

   LinearLayout layout = new LinearLayout(getActivity());
    layout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    layout.setOrientation(LinearLayout.HORIZONTAL);

    for (int j = 0; j <objectsTextToShow.size() ; j++) {

        TextView textCat = new TextView(getActivity());
        textCat.setText(Check.Languages(objectsTextToShow.get(j).getName(), LANGUAGE_ID));
        textCat.setTextSize(28);
        textCat.setLayoutParams(new TableLayout.LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1f));
        textCat.setTextColor(colorUtils.TITLE);
        textCat.setGravity(Gravity.CENTER);

        relativeLayout.addView(textCat);
        textCat.setBackgroundColor(colorUtils.backgroundColor);
        LinearLayout parentLayout = new LinearLayout(getActivity());
        parentLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, (float) 1.0));
        parentLayout.setOrientation(LinearLayout.HORIZONTAL);
        List<Item> items = new ArrayList<Item>();
        ListView listView = new ListView(getActivity());
        for (int i = 0; i <objectsTextToShow.get(j).getItems().size() ; i++) {
            items.add(objectsTextToShow.get(j).getItems().get(i));

        }

        listView.setAdapter(new ScrollAdapter(getActivity(), items));

        parentLayout.addView(listView);
        layoutItemDetail.addView(parentLayout);

        listView.setOnScrollListener(new AbsListView.OnScrollListener() {
            @Override
            public void onScrollStateChanged(AbsListView view, int scrollState) {

            }

            @Override
            public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {

            }
        });
    }
public void fillFormules(列出objectsTextToShow)
{
LinearLayout layoutItemDetail=(LinearLayout)view.findViewById(R.id.middle);
LinearLayout relativeLayout=(LinearLayout)view.findViewById(R.id.titles);
LinearLayout布局=新的LinearLayout(getActivity());
layout.setLayoutParams(新的LayoutParams(LayoutParams.MATCH_父级,LayoutParams.MATCH_父级));
布局。设置方向(线性布局。水平);

对于(int j=0;j您可以为用于显示列表中每个项目的
Linearlayout
设置固定高度。也可以将相同高度设置为
listView

LinearLayout parentLayout = new LinearLayout(getActivity());
        parentLayout.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, yourHeight, (float) 1.0));
在线性布局xml中:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="yourHeight"
android:orientation="horizontal" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_gravity="center"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:src="@drawable/ic_launcher" />

<TextView
    android:id="@+id/textView1"
    android:layout_gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:maxLines="3"
    android:textSize="25dp"
    android:text="TextView" />


您需要在行布局中进行调整。谢谢,我将此行添加到适配器
rowView.setLayoutParams(新的LinearLayout.LayoutParams(parent.getWidth(),parent.getHeight());
,它提供了我需要的东西,但上一个listview的高度和宽度值不正确。但还有一个问题,你的高度取决于屏幕,所以不能固定,对吗?这和我告诉你的想法是一样的(做同样的事情有很多方法)…无论如何..您可以在dp中传递高度的固定值,甚至可以获得设备的高度像素,并将屏幕高度的一小部分设置为线性布局的高度。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="yourHeight"
android:orientation="horizontal" >

<ImageView
    android:id="@+id/imageView1"
    android:layout_gravity="center"
    android:layout_width="48dp"
    android:layout_height="48dp"
    android:src="@drawable/ic_launcher" />

<TextView
    android:id="@+id/textView1"
    android:layout_gravity="center"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:maxLines="3"
    android:textSize="25dp"
    android:text="TextView" />