Android 具有水平方向的线性布局不会显示所有内容
我想在一行中显示三个布局,在下一行中显示下三个布局。 我以前使用过网格视图,但它用最后一项覆盖了我的所有内容,然后我应用了视图组并动态填充了该布局,但它没有显示在线性布局中。由于我使用的是选项卡布局,所以无法使用水平滚动视图。在滑动时,它将显示下一个选项卡Android 具有水平方向的线性布局不会显示所有内容,android,android-layout,Android,Android Layout,我想在一行中显示三个布局,在下一行中显示下三个布局。 我以前使用过网格视图,但它用最后一项覆盖了我的所有内容,然后我应用了视图组并动态填充了该布局,但它没有显示在线性布局中。由于我使用的是选项卡布局,所以无法使用水平滚动视图。在滑动时,它将显示下一个选项卡 package com.appknoll.studentdatacollection.midwayapp; import android.app.ActionBar; import android.graphics.Color; im
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>
package com.appknoll.studentdatacollection.midwayapp;
导入android.app.ActionBar;
导入android.graphics.Color;
导入android.os.Bundle;
导入android.support.v4.app.Fragment;
导入android.view.LayoutInflater;
导入android.view.view;
导入android.view.ViewGroup;
导入android.widget.GridView;
导入android.widget.LinearLayout;
导入android.widget.TextView;
导入java.io.IOException;
导入java.util.ArrayList;
导入java.util.List;
导入java.util.jar.Attributes;
公共类FragmentOne扩展了Fragment{
列表帖子=null;
XMLParser=新的XMLParser();
字符串strtext,text2;
文本视图部分标签;
视图组布局;
列表名称=新的ArrayList();
@凌驾
创建视图上的公共视图(布局、充气机、视图组容器、,
Bundle savedInstanceState){
视图根视图=充气机。充气(R.layout.fragment\u one,容器,false);
layout=(ViewGroup)rootView.findviewbyd(R.id.mainloayout);
section\u label=(TextView)rootView.findViewById(R.id.section\u label);
试一试{
posts=parser.parse(getActivity().getAssets().open(“rt_items.xml”);
for(XMLParserObject post:posts){
LinearLayout lii=新的LinearLayout(this.getContext());
lii.setLayoutParams(新的LinearLayout.LayoutParams(600600));
lii.设置填充(10,10,10,10);
立地资源(R.可提取边界);
lii.设置方向(线性布局。垂直);
布局。添加视图(lii);
TextView name=newtextView(this.getContext());
name.setLayoutParams(新的ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_内容,ViewGroup.LayoutParams.WRAP_内容));
name.setText(post.getName());
名称.setTextSize(30);
name.setTextColor(Color.parseColor(#191970”);
lii.addView(名称);
TextView价格=新的TextView(this.getContext());
Price.setLayoutParams(新的ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_内容,ViewGroup.LayoutParams.WRAP_内容));
Price.setText(Integer.toString(post.getUnit_Price())+“/-”;
价格.setTextSize(40);
Price.setTextColor(Color.parseColor(#FF0000”);
li.addView(价格);
TextView description=新的TextView(this.getContext());
description.setLayoutParams(新的ActionBar.LayoutParams(ViewGroup.LayoutParams.WRAP_内容,ViewGroup.LayoutParams.WRAP_内容));
description.setText(post.getDescription());
说明:SettexSize(15);
description.setTextColor(Color.parseColor(#000000”);
lii.addView(描述);
}
}捕获(IOE异常){
//TODO自动生成的捕捉块
e、 printStackTrace();
}
返回rootView;
}
}
//xml代码如下所示
我真的很惊讶一天之内没有答案:(
我的问题的答案是简单的流程布局。
在gradle.build中添加库
编译'org.apmem.tools:layouts:1。10@aar'"
然后简单地添加流程布局而不是线性布局。请想出一个更好的标题。
https://developer.android.com/reference/android/view/ViewGroup.html
不会向观察者传达任何信息。很抱歉,这是我关于堆栈溢出的第一个问题,所以下次我会非常小心:)您可以使用此链接修复:)