How to insert ListView or ViewPagers into fragment?
I am beginner of Android Programming. Here's my question. First I made a
xml-layout. here's my xml-layout(activity-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"
tools:context=".MainActivity" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="20"
>
<TextView
android:id="@+id/mainPicture"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="35"
android:text="1"
></TextView>
<TextView
android:id="@+id/ctxLibrry"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="65"
android:text="2"
></TextView>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="5"
>
<TextView
android:id="@+id/ctxLibrry2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="3"
></TextView>
</LinearLayout>
<fragment
android:name="com.example.s.a"
android:id="@+id/image_list_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="20"
/>
<fragment
android:name="com.example.s.b"
android:id="@+id/selected_list_fragment"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="40"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="5"
android:padding="5dp"
android:gravity="bottom|center"
>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="map"
></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="act"
></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="edu"
></Button>
<Button
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="back"
></Button>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
Excuted , the result is in the following pic.
![this image is activity_main.xml result.]
there's two fragment in layout.It's my initial step.
Now, my purpose is inserting (Viewpager or ListView) into fragment. So I
created another xml files named ListView.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" >
<ListView
android:id="@+id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ff00ffff"
/>
</RelativeLayout>
and I also made Java files. The First Java Main files is naemd
MainAcitivty.java
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
Second files is naemd a.java
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.ListView, container, false);
}
the last files is on the following.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment2, container, false);
}
Finally, I complied these files, the result is too much different from
what I originally think.
My thought was that ListView was exactly inside in fragment. But ListView
is out the fragment size,
even it covered the whole size of display..
when I tried TextView instance, it works well.. but change to ListView or
ViewPager.. the ListView size doesn't match with inserted fragment.
What is the problem? plz help me !!
No comments:
Post a Comment