水平方向的线性布局不会显示所有内容

时间:2017-04-28 11:40:02

标签: android android-layout

我想在一行中显示三个布局,在下一行显示下三个。 我之前使用的是网格视图,但是我用最后一项覆盖了我的所有内容,然后我应用了视图组并动态填充了该布局,但它没有以线性布局显示。因为我使用标签布局,所以我不能使用水平滚动视图。在滑动时,它将显示下一个标签。

package com.appknoll.studentdatacollection.midwayapp;    
import android.app.ActionBar;
import android.graphics.Color;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.GridView;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.jar.Attributes;


public class FragmentOne extends Fragment {

    List<XMLParserObject> posts = null;
    XMLParser parser = new XMLParser();
    String strtext, text2;
    TextView section_label;
ViewGroup layout;
   List<Attributes.Name> name = new ArrayList<Attributes.Name>();
    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.fragment_one, container, false);
        layout=(ViewGroup)rootView.findViewById(R.id.mainLayout);
        section_label = (TextView) rootView.findViewById(R.id.section_label);

       try {
            posts = parser.parse(getActivity().getAssets().open("rt_items.xml"));

            for (XMLParserObject post : posts) {


                LinearLayout lii=new LinearLayout(this.getContext());
                lii.setLayoutParams(new LinearLayout.LayoutParams(600,600));

                lii.setPadding(10,10,10,10);

                lii.setBackgroundResource(R.drawable.border);
                lii.setOrientation(LinearLayout.VERTICAL);

                layout.addView(lii);
                TextView name=new TextView(this.getContext());
                name.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                name.setText(post.getName());
                                name.setTextSize(30);
                name.setTextColor(Color.parseColor("#191970"));
                lii.addView(name);
                TextView Price=new TextView(this.getContext());
                Price.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                Price.setText(Integer.toString(post.getUnit_price())+"/-");
                Price.setTextSize(40);
                Price.setTextColor(Color.parseColor("#FF0000"));
                lii.addView(Price);
                TextView description=new TextView(this.getContext());
                description.setLayoutParams(new ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT));
                description.setText(post.getDescription());
                description.setTextSize(15);
                description.setTextColor(Color.parseColor("#000000"));
                lii.addView(description);

         }
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return rootView;
    }
    }

//xml code is below

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.appknoll.studentdatacollection.midwayapp.MainActivity$PlaceholderFragment">


    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fillViewport="false">

        <LinearLayout
            android:id="@+id/mainLayout"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_marginEnd="5dp"
            android:layout_marginStart="5dp"

            android:orientation="horizontal"
            >


        </LinearLayout>
    </ScrollView>

</RelativeLayout>

1 个答案:

答案 0 :(得分:0)

我很惊讶在一天内没有回答:( 我的问题的答案很简单。 在gradle.build中添加库 &#34;编译&#39; org.apmem.tools:layouts:1.10@aar'&#34; 然后只需添加流程布局而不是线性布局。

相关问题