如何将按钮放置在 Textview 的中间

发布于 2024-12-21 02:49:11 字数 1231 浏览 5 评论 0原文

我试图让两个 android 按钮出现在两个文本视图之间。但是第一个文本视图似乎正在显示,而其他文本视图和按钮没有出现。我希望它看起来像:

“等等等等等等按钮等等等等按钮”

我看到的是:

“等等等等 按钮”哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈哈等等等等“

这是代码:

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

任何帮助将不胜感激!

I am trying to get two android buttons to appear inbetween two textviews. But the first textview seems to be showing while the other textview and buttons are not appearing. I want it to look like:

"Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah BUTTON blah blah blah blah blah blahblah blah blah blah blah blah BUTTON"

What I am seeing is:

"Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah "

Here is the code:

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

Any help would be greatly appreciated!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

缘字诀 2024-12-28 02:49:11

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

检查此以获取有关布局的更多信息。

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

You better use layout weights or relative layout to achieve what you want.

Check this for more info on layouts.

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

允世 2024-12-28 02:49:11

则权重属性设置为 1 的控件将根据其宽度进行同等调整

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

尝试下面的代码并记住,如果宽度属性设置为 Fill_parent

try below code and remember that controls having weight property set as 1 will be equally adjusted accroding to their width if width property set to 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

烛影斜 2024-12-28 02:49:11

您可以轻松地提供“布局宽度”属性作为“dp”值。

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

You can go easily with providing "Layout width" attribute as "dp" value.

One other thing about your code not for your question. You may have use "android:text" attributes with values in here in order to clearly express your question. But if not, this is a bad practice. Try to put your String values always in the "strings.xml" file where you can find under the "values" directory.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文