在android中定义碎片布局的高度和位置
我在Android布局中使用片段。如何设置碎片布局的高度 这是activity\u main.xml在android中定义碎片布局的高度和位置,android,xml,android-layout,user-interface,android-fragments,Android,Xml,Android Layout,User Interface,Android Fragments,我在Android布局中使用片段。如何设置碎片布局的高度 这是activity\u 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" a
<?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>
<?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>
这是fragment.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>
<?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>
我需要设置碎片的最大高度和碎片的位置。我怎样才能做到这一点呢?我不知道有什么大问题。可以像任何其他视图一样设置片段的属性(例如:高度、重量等) 因此,设置碎片高度的正确方法是 这将是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:id="@+id/fragment_place"
android:name="com.android.fragmentstest.FragmentOne"
android:layout_width="match_parent"
android:layout_height="90dp" />
</LinearLayout>
请注意,Android:layout_height=“90dp”定义了主要活动中片段的高度。您想实现什么?您的问题不清楚..谢谢。这正是我需要知道的。如果片段的内容是可变大小的,并且片段需要是包装内容,该怎么办?在xml声明中设置wrap_内容似乎不起作用。片段就是不显示。