我正在编写一个在 Nexus10 上运行的应用程序。我认为不重要。我使用 Android版本4.4.2 。
我正在尝试使用片段来显示一个TextViews
的公共组,这组显示为使用Activity
的{{1}}的前3个元素。
我没有在以下两个LinearLayout
XML代码段之外进行任何格式化操作。
在第一个(父级)中,我有一个片段和两个文本视图。片段与LinearLayout
之间存在巨大差距。如果我从片段标记中删除TextViews
和android:layout_height="0dp"
属性,则片段根本不会显示。有谁知道为什么我可能会在片段和它下面显示的两个TextView之间得到这个巨大差距?谢谢!
这是父级(android:layout_weight="1"
)级别布局。下面是Activity
特定布局。
fragment
以下是特定于片段的布局。
<?xmlversion="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"
androidrientation="vertical" >
<fragment
android:name="com.srcinc.drphilos.ChemicalNameAndC asNumberFragment"
android:id="@+id/chemical_name_and_cas_number"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TextView
android:id="@+id/healthEffectsSummaryLabel"
android:textStyle="bold"
style="@android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/toxletText"
style="@android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
答案 0 :(得分:0)
使用
android:layout_height="0dp"
android:layout_weight="1"
你告诉片段增长并填满屏幕中的所有空白区域。
如果您想要的是TextViews出现在片段之后,那么您应该放置的参数是wrap_content:
<fragment
android:name="com.srcinc.drphilos.ChemicalNameAndC asNumberFragment"
android:id="@+id/chemical_name_and_cas_number"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
答案 1 :(得分:0)
试试这个,
<?xmlversion="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"
androidrientation="vertical" >
<fragment
android:name="com.srcinc.drphilos.ChemicalNameAndC asNumberFragment"
android:id="@+id/chemical_name_and_cas_number"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8"
/>
<TextView
android:id="@+id/healthEffectsSummaryLabel"
android:textStyle="bold"
style="@android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TextView
android:id="@+id/toxletText"
style="@android:style/TextAppearance.Medium"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_weight="1"
/>
这会将整个屏幕划分为8部分片段和1:1部分TextViews。如果这不是您正在寻找的,请告诉我。