簡體   English   中英

Android:LinearLayout中的Fragment和TextView之間存在差距

[英]Android: Gap between Fragment and TextView in LinearLayout

我正在編碼在Nexus10上運行的應用程序。 我認為沒關系。 我正在使用4.4.2版的Android

我正在嘗試使用片段顯示一組普通的TextViews ,這些TextViews顯示為使用LinearLayoutActivity的前3個元素。

在以下兩個LinearLayout XML代碼段之外,我沒有進行任何格式化。

在第一個(父級別)中,我有一個片段和兩個文本視圖。 在片段和TextViews之間存在巨大的差距 如果我從fragment標簽中刪除android:layout_height="0dp"android:layout_weight="1"屬性,則該片段根本不會顯示。 有誰知道為什么我可能在片段和下面顯示的兩個TextViews之間出現如此巨大的差距 謝謝!

這是父級( 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>

接下來是片段特定的布局。

<LinearLayout xmlns:android=http://schemas.android.com/apk/res/android
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    androidrientation="vertical" >  
    <TextView
        android:id="@+id/chemicalName"
        android:textStyle="bold" 
        style="@android:style/TextAppearance.Large"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView
        android:id="@+id/casNumberText" 
        style="@android:style/TextAppearance.Large"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"/>
    <TextView 
        android:layout_width="fill_parent" 
        android:layout_height="5dp" 
        android:background="#DADADA" />
</LinearLayout>

隨着

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" 
/>

嘗試這個,

<?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。 讓我知道這是否不是您想要的。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM