线性布局内的文本

时间:2013-05-03 11:49:54

标签: android android-layout android-linearlayout textview

我有一个线性布局,其中我有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>

谢谢和问候,

4 个答案:

答案 0 :(得分:0)

首先删除此android:layout_marginBottom="0"这不起作用。然后删除android:layout_weight="1",以便将两个文本视图保留在linearayout中。 TextView layout_height应为wrap_content。它会工作检查。 textview size param sp

答案 1 :(得分: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

答案 2 :(得分:-1)

将两个宽度都更改为wrap_content 因为目前每个TextView占据屏幕宽度的一半,并将文本与其中心对齐。

答案 3 :(得分:-1)

根据您提供的信息,我认为您的问题是因为match_parent用于layout_height的{​​{1}}。通过这样做,你要求他们采取TextView给出的所有高度。

尝试LinearLayout

相关问题