由於某些原因,我將添加到我的RelativeLayout中的滾動視圖中的LinearLayouts彼此重疊。 我認爲有一些方法可以設置LinearLayouts,以便將它們放置在上面的LinearLayout之下?線性佈局重疊
exampleLayout = (RelativeLayout)findViewById(R.id.examplelayout);
exampleButton = new TextView[exampleListCount];
LinearLayout.LayoutParams rowsLayoutParams = new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
rowsLayoutParams.gravity = Gravity.CENTER;
rowsLayoutParams.setMargins(10, 10, 10, 0);
LinearLayout.LayoutParams exampleButtonParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
exampleButtonParams.setMargins(10, 10, 10, 0);
exampleRowLayoutArray = new LinearLayout[rowsNeededInt];
int exampleAddedCount = 0;
for(int x = 0; x < rowsNeededInt; x++){
exampleRowLayoutArray[x] = new LinearLayout(this);
exampleRowLayoutArray[x].setOrientation(LinearLayout.HORIZONTAL);
exampleRowLayoutArray[x].setLayoutParams(rowsLayoutParams);
for(int i =0; i < 6; i++){
if(exampleAddedCount < examplerListCount){
String exampleNo = String.valueOf(exampleList.get(exampleAddedCount));
exampleButton[exampleAddedCount] = new TextView(this);
exampleButton[exampleAddedCount].setId(exampleAddedCount+1);
exampleButton[exampleAddedCount].setGravity(Gravity.CENTER);
exampleButton[exampleAddedCount].setText(exampleNo);
exampleButton[exampleAddedCount].setLayoutParams(exampleButtonParams);
exampleButton[exampleAddedCount].setTextColor(getResources().getColor(android.R.color.white));
exampleButton[exampleAddedCount].setTextSize(TypedValue.COMPLEX_UNIT_DIP, 24);
exampleButton[exampleAddedCount].setBackgroundDrawable(new BitmapDrawable(getResources(), ButtonNormal));
exampleRowLayoutArray[x].addView(exampleButton[exampleAddedCount]);
exampleAddedCount++;
}
}
exampleLayout.addView(exampleRowLayoutArray[x]);
}
的Xml
<ScrollView
android:id="@+id/examplescrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_below="@+id/topbar">
<RelativeLayout
android:id="@+id/examplelayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
</RelativeLayout>
</ScrollView>
如果您使用的是linearlayouts數組,爲什麼不使用ListView而不是相對佈局? –