设置按钮对准编程 [英] Setting button alignment programmatically

查看:165
本文介绍了设置按钮对准编程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我动态创建了50键。结果
作为后面的文本是越来越设置:

I'm creating some 50 button dynamically.
Text is getting set as followed:

btn.Text=result.Rows[i]["Col1"].ToString()+"\n"+result.Rows[i]["Col2"].ToString()
+"\n"+result.Rows[i]["Col3"].ToString();

其中,结果数据表&安培; BTN 是按钮对象。

where result is DataTable & btn is object for button.

现在的问题是一些按钮没有得到适当的显示。

Now the problem is some of the buttons are not getting displayed appropriately.

参照下面截图中,

在IMG1 - 是越来越显示了一个不必要的空行的第一行后结果。
在IMG2 - 文本不居中对齐结果。
在IMG3 - 塔塔汽车的是没有得到显示在单行即使有对T两侧的空间,他按钮

in img1 - An unnecessary blank line is getting displayed after the first row.
in img2 - Text is not center aligned.
in img3 - TATAMOTORS is not getting displayed in single line even though there is a space on either side of t he button.

请注意,我的设置不填充可以是这样做的原因。

Please note that I'm not setting padding which can be the reason for this.

不知道如何解决这个问题?结果
此外,如何一键文本对齐方式可以设置的编程

Any idea how to solve this?
Also, how alignment of text of a button can be set programmatically?

我知道这是不是最好的问题,但它花费数小时后,我无法破解它。

I know that this is not the Best of the question, but after spending hours on it, I'm unable to crack it.

任何帮助AP preciated ...

推荐答案

您可以设置按钮的重力自定义文本的对齐方式。这是通过使用重力属性公开上的按钮。从文档

You can set the gravity of the button to customize how the text is aligned. This is exposed on the button by using the Gravity property. From the docs:

设定的文本和将要使用的垂直重力的水平取向时,有在超出了所需的文字本身的TextView的额外的空间。

Sets the horizontal alignment of the text and the vertical gravity that will be used when there is extra space in the TextView beyond what is required for the text itself.

您可以分配的值在 GravityFlags枚举。例如:

The values you can assign are found in the GravityFlags enum. For example:

button.Gravity = GravityFlags.Center;

这篇关于设置按钮对准编程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆