Ich verwende Fragmente in meinem Android-Layout. Wie stelle ich die Höhe des Fragmentlayouts ein?
Dies ist activity_main.xml
<?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" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Fragment No.1"
android:onClick="selectFrag" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="selectFrag"
android:text="Fragment No.2" />
<fragment
android:name="com.android.fragmentstest.FragmentOne"
android:id="@+id/fragment_place"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
Das ist fragment.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="40dp"
android:layout_height="20dp"
android:id="@+id/tutlist_fragment"
android:layout_weight="45"
android:background="#7bae16">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_weight="1"
android:text="This is fragment No.1"
android:textStyle="bold" />
</RelativeLayout>
Ich muss die maximale Höhe des Fragments und die Position des Fragments festlegen. Wie werde ich das erreichen?
Antworten:
1 für die Antwort № 1Ich sehe nicht, was das große Problem ist. Es ist möglich, Attribute eines Fragments genau wie jede andere Ansicht festzulegen (zB: Höhe, Gewicht, etc.)
Also wird die korrekte Höhe des Fragments eingestellt
Dies wird die activity_main.xml-Datei sein Sie müssen die Layouthöhe nicht in den einzelnen Fragmenten selbst definieren.
<?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" >
<Button
android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Fragment No.1"
android:onClick="selectFrag" />
<Button
android:id="@+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:onClick="selectFrag"
android:text="Fragment No.2" />
<fragment
android:id="@+id/fragment_place"
android:name="com.android.fragmentstest.FragmentOne"
android:layout_width="match_parent"
android:layout_height="90dp" />
</LinearLayout>
Beachten Sie das Android: layout_height = "90dp" definiert die Höhe des Fragments in der Hauptaktivität.