我遇到了一个问题,我不能把我的dataGridView放到scrollView中,如果我有很多列,它们就会变得很薄,以至于无法看到那里的东西。这就是为什么我决定重新制作并使用垂直布局为每列创建LinearLayout,并且每个列都将使用另一个水平布局的LinearLayout来模拟GridView。 (希望它是一个好主意)
但不幸的是,我在创作过程中遇到了一些问题。它没有被创建,我的应用程序关闭。向你寻求帮助
以下是我的代码:
grid_container.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/GridScrollView"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/main_grid_layout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>
PageFragment.java(应填写LinearLayout的地方)
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.grid_container, container, false);
LinearLayout mainLayout = (LinearLayout) view.findViewById(R.id.main_grid_layout);
int colCount = mPage.get(0).split(",").length;
int rowCount = mPage.size();
ArrayList<ArrayList<String>> tempNormList = createNormList(mPage);
for(int currCol=0;currCol<colCount;currCol++){
LinearLayout linearLayout = new LinearLayout(view.getContext());
linearLayout.setOrientation(LinearLayout.HORIZONTAL);
LinearLayout.LayoutParams llParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
linearLayout.setLayoutParams(llParams);
for(int currRow=0; currRow<rowCount;rowCount++){
TextView textView = new TextView(view.getContext());
textView.setText(tempNormList.get(currCol).get(currRow));
if(currRow==0){
textView.setBackgroundResource(R.drawable.header_borders);
}
linearLayout.addView(textView);
}
mainLayout.addView(linearLayout);
}
return view;
}
提前感谢您的帮助
答案 0 :(得分:0)
尝试我的链接答案,它将提供您的解决方案,但您已做了一些更改,如下所示
for
循环使用getView()
方法
CustomAdapter设置数据。通过`findViewById()投放您的Linearlayout
,其ID为main_grid_layout
。
将getView()
方法的convertView添加到main_grid_layout
Skip Item Android Grid View in condition
希望它会帮助你