Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了Android layout_weight不工作大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在制作一个带有5个按钮的片段.当它在像平板电脑这样的大屏幕上时,我会使用一个片段将所有5个按钮放在顶部.我将所有layout_width设置为1,但按钮不会像预期的那样在屏幕上均匀分布.

预期
[全部] [我的] [按钮] [转] [这里]

我得到了什么
b1 b2 b3 b4 b5 b3和b5只是一个按钮…只是显示它打破了一个
[全部] [我] [但] [去] [她]并将其排成一行.
         [吨] [e]

我一直在玩它并尝试不同的东西,但我不能让它改变.任何帮助表示赞赏.谢谢.

<?xml version="1.0" encoding="utf-8"?>

<LinearLayout
xmlns:android="http://scheR_349_11845@as.android.com/apk/res/android"
android:id="@+id/xlarge_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">

<Button
    android:id="@+id/tip_btn"
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:text="@String/tip_button"
    android:onClick="tipButton">
</Button>

<Button
    android:id="@+id/preference"
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:text="@String/setTings"
    android:onClick="showPreferences">
</Button>

<Button
    android:id="@+id/rate_btn"
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:text="@String/rate_button"
    android:onClick="rateButton">
</Button>

<Button
    android:id="@+id/FeedBACk_btn"
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:text="@String/FeedBACk_button"
    android:onClick="FeedBACkButton">
</Button>

<Button
    android:id="@+id/cancel_btn"
    android:layout_width="0px"
    android:layout_height="wrap_content"
    android:layout_weight="2"
    android:text="@String/exiT_Button"
    android:onClick="cancelButton">
</Button>
</LinearLayout>

解决方法

简答:将按钮的layout_width设置为0. layout_weight用于确定如何在布局中的元素之间传播剩余空间.因此,如果未将宽度设置为零,则按钮内容的大小将影响它们的大小.

这里有两篇很好的博客文章解释了权重如何工作:

http://blog.stylingandroid.com/archives/297http://blog.stylingandroid.com/archives/312

大佬总结

以上是大佬教程为你收集整理的Android layout_weight不工作全部内容,希望文章能够帮你解决Android layout_weight不工作所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。