0

我有一個線性佈局,其中有2個文本視圖。但是在文本視圖之間有一些填充。如何刪除填充?我附上了一個截圖和源代碼。線性佈局內的文本

我不需要33%和完成之間的任何空間。

截圖:https://www.dropbox.com/s/e69loke90q9c6nt/snip4.PNG

代碼:

<TextView 
     android:id="@+id/toptext" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:layout_margin="0dp" 
     android:layout_marginBottom="0" 
     android:layout_weight="1" 
     android:gravity="center_vertical" 
     android:text="33%" 
     android:textSize="24sp" /> 

    <TextView 
     android:id="@+id/bottomtext" 
     android:layout_width="fill_parent" 
     android:layout_height="match_parent" 
     android:layout_weight="1" 
     android:gravity="center_vertical" 
     android:singleLine="true" 
     android:text="Completed" 
     android:textSize="10dp" /> 

</LinearLayout> 

全碼

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:padding="6dip"> 
    <TextView 
      android:id="@+id/deckno" 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:layout_weight="1" 
      android:text="Deck 1" 
      android:textSize="24dp" 
      android:gravity="center_vertical" 
     /> 
    <LinearLayout 
     android:orientation="vertical" 
     android:layout_width="fill_parent" 
     android:layout_weight="1" 
     android:layout_height="fill_parent"> 

     <TextView 
      android:id="@+id/toptext" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:layout_margin="0dp" 
      android:layout_marginBottom="0" 
      android:layout_weight="1" 
      android:gravity="center_vertical" 
      android:text="33%" 
      android:textSize="24sp" /> 

     <TextView 
      android:id="@+id/bottomtext" 
      android:layout_width="fill_parent" 
      android:layout_height="match_parent" 
      android:layout_weight="1" 
      android:gravity="center_vertical" 
      android:singleLine="true" 
      android:text="Completed" 
      android:textSize="10dp" /> 

    </LinearLayout> 
</LinearLayout> 

感謝和問候,

+0

在這裏展示您的詳細XML代碼,這將是很容易找到的錯誤在你的代碼 – 2013-05-03 11:52:51

+0

這單獨產生問題 – 2013-05-03 11:54:08

+0

這可能是因爲爲'TextView'提供了'layout_weight'。顯示完整的版面 – Renjith 2013-05-03 11:54:08

回答

0

您還可以使用線性佈局。但我建議你使用相對佈局。下面根據您的需要

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
> 

<TextView 
    android:id="@+id/toptext" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:text="33%" 
    android:textSize="24sp" /> 

<TextView 
    android:id="@+id/bottomtext" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/toptext" // place textview below toptext 
    android:singleLine="true" 
    android:text="Completed" 
    android:textSize="10dp" /> 

</RelativeLayout> 
修改

enter image description here

編輯:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="fill_parent" 
android:orientation="horizontal" 
android:padding="6dip"> 

<TextView 
    android:id="@+id/deckno" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:gravity="center_vertical" 
    android:text="Deck 1" 
    android:textSize="24dp" /> 

<RelativeLayout 
    android:layout_width="wrap_content" 
android:layout_height="wrap_content" 
android:paddingLeft="40dp" 
> 

<TextView 
    android:id="@+id/toptext" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_alignParentTop="true" 
    android:text="33%" 
    android:textSize="24sp" /> 

<TextView 
    android:id="@+id/bottomtext" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentLeft="true" 
    android:layout_below="@+id/toptext" 
    android:singleLine="true" 
    android:text="Completed" 
    android:textSize="10dp" /> 

</RelativeLayout> 
</LinearLayout> 

enter image description here

+0

上面提到的正是我所需要的。但是當我複製代碼時,它沒有顯示任何東西。 – 2013-05-03 12:10:24

+0

@GeoPaul它的工作原理。這就是我從圖形預覽 – Raghunandan 2013-05-03 12:11:37

+0

@GeoPaul檢查編輯時發佈快照的原因。相應地修改。建議不要使用硬編碼的字符串 – Raghunandan 2013-05-03 12:18:28

-1

變化既寬度以wrap_content ,因爲目前各TextView需要半個屏幕寬度和對齊到它的中央的文字。

-1

從您提供的信息中,我認爲您的問題是因爲您使用match_parent代替TextView s的layout_height。通過這樣做,你可以讓他們採取由LinearLayout給出的所有高度。

嘗試wrap_content

+0

我改變了兩個wrap_content但沒有區別。 – 2013-05-03 11:58:22

+0

@GeoPaul使用相對佈局 – Raghunandan 2013-05-03 12:01:51

+0

@GeoPaul:嘗試刪除'layout_weight' – tbruyelle 2013-05-03 12:04:22

0

首先刪除此android:layout_marginBottom="0"這是不行的。然後刪除android:layout_weight="1"兩個textviews保持在linearayout。 TextView layout_height應該是wrap_content。它會工作檢查。 textview大小參數sp