我有一個的LinearLayout:機器人:LinearLayout中與水平方向推壓關閉屏幕元件
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
</LinearLayout>
</ScrollView>
其中我填充動態添加片段
void add_item(){
Database database = new Database(this);
String[] categories = database.getCategories();
LinearLayout layout = (LinearLayout)findViewById(R.id.container);
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
if (categories.length>0) {
for (String category : categories){
FrameLayout frame = new FrameLayout(this);
int id = View.generateViewId();
frame.setId(id);
layout.addView(frame);
Fragment itemsFragment = CategoryFragment.newInstance(R.drawable.body, category);
ft.add(id, itemsFragment);
}
Log.i("test","success");
}
ft.commit();
}
的問題是碎片離開屏幕。我實際上想要水平碎片,並且只在空間不足時移動到下面。可能嗎?
如果你不改變線性佈局,以垂直的方向是什麼? –
@AjilO。如果我這樣做,他們將排隊作爲列 –
好吧。這是從剛剛讀書的問題once.To得到更好的反應很可能需要添加到你真正想要的水平碎片的問題,並在下面移動,只有當你運行的空間有點不清楚。 :) –