2011-12-11 56 views
0

我想让两个android按钮出现在两个textviews之间。但是第一个textview似乎正在显示,而另一个textview和按钮没有出现。我希望它看起来像:如何在Textviews中放置按钮

“等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等按钮等等等等等等等等等等blahblah等等等等等等等等等等BUTTON”

什么我看到的是:

“等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等等”

下面是代码:

<LinearLayout android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 
    <TextView 
     android:text="Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah " 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:text="BUTTON" 
     android:background="@null" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <TextView 
     android:text=" blah blah blah blah blah blahblah blah blah blah blah blah " 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
    <Button 
     android:text="BUTTON" 
     android:background="@null" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" /> 
</LinearLayout> 

任何帮助将不胜感激!

回答

0

尝试下面的代码,并记住其重量属性设置为1的控制将平均调整accroding他们的宽度,如果宽度属性设置为FILL_PARENT

<LinearLayout android:layout_width="fill_parent" 
    android:orientation="horizontal" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_height="fill_parent"> 
    <TextView 
     android:text="Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah " 
     android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="fill_parent"/> 
    <Button 
     android:text="BUTTON" 
     android:background="@null" 
     android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="fill_parent" android:textColor="#ffffff"/> 
    <TextView 
     android:text=" blah blah blah blah blah blahblah blah blah blah blah blah " 
     android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="fill_parent"/> 
    <Button 
     android:text="BUTTON" 
     android:background="@null" 
     android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="fill_parent" android:textColor="#ffffff"/> 
</LinearLayout> 

enter image description here

1

你最好使用布局权重或相对布局来实现你想要的。

检查此以了解更多布局信息。

http://developer.android.com/guide/topics/ui/layout-objects.html

+0

您好Serdar,感谢您的快速响应,请您提供一个如何使用布局权重来实现我想要的示例? – c8apps

+0

检查这个链接这是你的最好例子。 http://developer.android.com/resources/tutorials/views/hello-linearlayout.html –

0

你可以提供“布局宽度”属性作为“dp”值很容易。

另一件关于你的代码不适合你的问题。你可能在这里使用带有值的“android:text”属性来清楚地表达你的问题。但如果不是,这是一个不好的做法。尝试将字符串值始终放在“strings.xml”文件中,您可以在“values”目录下找到它。