2011-11-23 62 views
6

我得到了一个正常的按钮,但文本是截断的。我不知道为什么会发生。为什么我的Button文本被截断?

任何人都可以分析它为什么发生?

代码:

<TextView 
     android:id="@+id/txt_project_title" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:gravity="center_horizontal" 
     android:text="Default Title" 
     android:textColor="@android:color/white" 
     android:textStyle="bold" 
     android:textSize="19sp" 
     android:shadowColor="#000000" 
     android:shadowDx="1.5" 
     android:shadowDy="1.5" 
     android:shadowRadius="1" 
     /></LinearLayout> 
     <ScrollView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content"> 

     <LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_gravity="center" 
    android:background="@drawable/whitebg" 
    android:layout_marginTop="5dp" 
    android:layout_marginBottom="5dp" 
    android:orientation="vertical"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="3dp" 
    > 
    <ImageView 
     android:id="@+id/project_image" 
     android:layout_marginLeft="10dp" 
     android:layout_marginTop="10dp" 
     android:layout_width="100dp" 
     android:layout_height="100dp" 
     android:layout_weight="3" 
     android:layout_gravity="center_vertical"/> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentRight="true" 
    android:padding="10dp" 
    android:layout_weight="5" 
    > 

    <TextView 
     android:id="@+id/txt_project" 
     android:layout_width="181dp" 
     android:layout_height="wrap_content" 
     android:text="Project Title" 
     android:textColor="#0e3946" 
     android:textSize="16sp" 
     android:textStyle="bold" /> 

    <TextView 
     android:id="@+id/txt_organization_title" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:text="Organization Title" 
     android:textSize="13sp" 
     android:textStyle="italic" 
     android:textColor="#20822c"/> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="horizontal" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="3dp" 
    > 
    <CheckBox android:id="@+id/checkbox" 
     android:layout_width="wrap_content" 
     android:button="@android:drawable/btn_star" 
     android:layout_gravity="center" 
     android:layout_height="wrap_content"/> 

     <TextView 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center" 
      android:text="als Favorit markieren" 
      android:textColor="#000000" 
      android:textSize="12sp" /> 

    </LinearLayout> 

     <TextView 
      android:layout_marginTop="3dp" 
      android:layout_marginLeft="3dp" 
      android:id="@+id/txt_amount" 
      android:layout_width="wrap_content" 
      android:layout_height="15dp" 
      android:textStyle="bold" 
      android:textColor="#0E3946" 
      android:textSize="12sp" 
      android:text=" " 
      android:layout_alignParentRight="true" 
      /> 

     <Button 
      android:layout_marginTop="3dp" 
      android:id="@+id/btn_sms_spenden" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Jetzt Spenden!" 
      android:textSize="13sp" 
      android:textColor="#0e3946" 
      android:textStyle="bold" 
      /> 
     </LinearLayout> 
</LinearLayout> 

图片:

See the red circled area

+3

尝试添加填充到按钮 – aNi

+0

您可以发布它作为一个答案,我会接受它。 – hectichavana

回答

19

尝试添加填充到该按钮

安卓填充

0

变化线

android:layout_height="wrap_content" 

android:layout_height="20dp" //or above to 20dp then check 

在您的xml按钮部分...

+0

android:layout_marginTop =“3dp” 不应该影响文本内部的位置。 – josephus

+0

取回已移除的行并给android:layout_height =“20dp” –

+0

使用android:layout_height =“20dp”或更多,该按钮被切断。我已经删除了重量,但它似乎不工作 – hectichavana

1

问题可能与您使用的android:layout_weight ..它主要用于控制/分配视图内的空间。

+0

可能。由于按钮的LinearLayout父项具有android:layout_weight =“5”,因此按钮可能没有“wrap_content”,因为它应该正确。我试图在我的图形布局查看器,它的工作原理。 – josephus

0

只是想给答案,

1)@Last战士说,尝试去除余量

2)你必须定义文本13SP的大小,我认为有因为没有足够的空间13sp因为按钮下面的布局

3)您必须给布局包含Button和所有XML的上部布局的固定大小或Weight属性,以便空间在Button处结束并且文本被切割。

4)尝试给wrap_content或fill_parent添加大小,如果你使用了权重,那么看到你在dp/sp中的大小没有超出权重范围。

+0

我改变了我的答案。你是对的科学怪人 –

+0

我已经删除了重量,但它似乎并没有工作 – hectichavana

+0

你可以发布你的整个XML代码使用www.pastebin.com并给这里链接到..所有可以得到你在做什么? – MKJParekh