Android TableLayout中的按钮宽度

Android TableLayout中的按钮宽度,第1张

概述我有一个TableLayout,底部有一个按钮.我的问题是,即使我不想要那么宽,按钮也可以填充列的整个宽度. XML如下所示: <?xml version="1.0" encoding="utf-8"?><TableLayout xmlns:android="http://schemas.android.com/apk/res/android" android:stretchColumn 我有一个tableLayout,底部有一个按钮.我的问题是,即使我不想要那么宽,按钮也可以填充列的整个宽度.

XML如下所示:

<?xml version="1.0" enCoding="utf-8"?><tableLayout  xmlns:androID="http://schemas.androID.com/apk/res/androID"  androID:stretchColumns="*"  androID:layout_wIDth="wrap_content"  androID:layout_height="wrap_content">   <tableRow androID:layout_height="wrap_content"        androID:layout_wIDth="fill_parent">      <CheckBox androID:ID="@+ID/check1"      androID:layout_wIDth="wrap_content"      androID:layout_height="wrap_content"       androID:text="Some text 1"/>     <CheckBox androID:ID="@+ID/check2"      androID:layout_wIDth="wrap_content"      androID:layout_height="wrap_content"      androID:text="Some text 1"/>   </tableRow>   <tableRow androID:layout_height="wrap_content"        androID:layout_wIDth="fill_parent">       <CheckBox androID:ID="@+ID/check3"      androID:layout_wIDth="wrap_content"      androID:layout_height="wrap_content"       androID:text="Even some more text 2"/>     <CheckBox androID:ID="@+ID/check4"      androID:layout_wIDth="wrap_content"      androID:layout_height="wrap_content"      androID:text="Even some more text 2"/>   </tableRow>    <tableRow androID:layout_height="wrap_content"        androID:layout_wIDth="fill_parent">      <CheckBox androID:ID="@+ID/check5"      androID:layout_wIDth="wrap_content"      androID:layout_height="wrap_content"       androID:text="An even longer line of text 3"/>     <CheckBox androID:ID="@+ID/check6"      androID:layout_wIDth="wrap_content"      androID:layout_height="wrap_content"      androID:text="Another longer line of text 3"/>    </tableRow>   <EditText      androID:ID="@+ID/myEditText1"      androID:layout_wIDth="fill_parent"       androID:layout_height="wrap_content"      androID:inputType="textMultiline"      androID:singleline="false"      androID:text="Enter some text"    />   <tableRow>    <button androID:ID="@+ID/Savebutton"      androID:layout_wIDth="wrap_content"       androID:layout_height="wrap_content"      androID:text="Save">  </button>   </tableRow>       </tableLayout>

即使我设置一个明确的宽度的按钮,它忽略它.例如,如果我有:

<button androID:ID="@+ID/Savebutton"      androID:layout_wIDth="100sp"      androID:layout_height="100sp"      androID:text="Save">  </button>

…按钮变得更高,但宽度仍然延伸以填充列.

我希望按钮大约是当前宽度的一半,以列为中心.提前致谢!!

解决方法 @mbaird是正确的:androID:stretchColumns =“*”总是拉伸列的宽度.但是,您仍然可以通过将FrameLayout放入列的宽度列,然后将按钮放在列中,从而获得列中所需的行为.然后,您可以根据需要设置按钮的大小,并将其置于FrameLayout中:
<tableRow>    <FrameLayout        androID:layout_height="wrap_content">        <button            androID:ID="@+ID/Savebutton"            androID:layout_wIDth="wrap_content"            androID:layout_height="wrap_content"            androID:layout_gravity="center"            androID:paddingleft="40dp"            androID:paddingRight="40dp"            androID:text="Save">        </button>    </FrameLayout></tableRow>
总结

以上是内存溢出为你收集整理的Android TableLayout中的按钮宽度全部内容,希望文章能够帮你解决Android TableLayout中的按钮宽度所遇到的程序开发问题。

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

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1132602.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存