Reputation:
I searched for a while and find no awnser and i must say that i'm very new in creating apps
i read the categorys(name, discription) from a sqlite database (i dont know how many categorys are an this database),
now i create a horizontal slider contains linearlayout(horizontal).
in this linearlayout i will create dynamically framelayout (contains custom xml code like other framelayouts, linearlayouts ect.)
i dont know how can i insert the xml ...
i hope someone can help me to find a solution for this problem
--- EDIT ---
the main activity
public class MainActivity extends Activity {
int scr_w, scr_h;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Display display = getWindowManager().getDefaultDisplay();
Point size = new Point();
display.getSize(size);
scr_w = size.x;
scr_h = size.y;
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.menu_box_layout, null, false);
LinearLayout llTest = (LinearLayout)findViewById(R.id.horilila);
//Create the Menu Boxes here
for(int i =1;i<=6; i++){
FrameLayout flTest = new FrameLayout(this);
flTest.addView(v, scr_w, LayoutParams.MATCH_PARENT);
flTest.setId(i + 10);
//Insert the new FrameLayout into the LinearLayout
llTest.addView(flTest);
}
}
the main xml:
<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:gravity="fill"
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=".MainActivity" >
<FrameLayout
android:id="@+id/mailLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="@+id/horilila"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
</LinearLayout>
</HorizontalScrollView>
</FrameLayout>
the layout for menu box, that i will insert:
<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:gravity="fill"
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=".MainActivity" >
<FrameLayout
android:layout_height="match_parent"
android:background="#fab3ff" >
<TextView
android:text="This is a test..." />
</FrameLayout>
</RelativeLayout>
Upvotes: 0
Views: 3101
Reputation: 11234
Let's imagine you have a xml, you can get a view from it like that:
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View v = inflater.inflate(R.layout.<your_xml>, null, false);
Then you can add this view to your LinearLayout:
linearLayout.addView(v);
Upvotes: 3