1

My main xml layout file....

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/relLayoutPlayerActivity"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/backgroundimage"
    android:orientation="vertical" >

</LinearLayout>

I created the viewpager.....

that layout file......

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <android.support.v4.view.ViewPager
       android:id="@+id/carousel_layout_home"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:overScrollMode="never" />

</LinearLayout>

I load the images into this view pager by creating three classes & another xml file...... now I want to add this viewpager into linearlayout of main xml file....

It means I want dynamically view the viewpager in mainxml file. how to that? pls give me answer

thankyou

4

1 回答 1

0

如果您有两个布局,例如LinearLayout您可以使用addView(). 在您的Activity情况下,它看起来类似于,

LinearLayout layout = (LinearLayout) findViewById(R.id.relLayoutPlayerActivity);
LayoutInflater inflater = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
layout.addView(inflater.inflate(R.layout.idOfLayoutHoldingYourViewPager, null));
于 2013-08-11T08:22:50.377 回答