编程的Andr​​oid按钮位置 [英] Android Button Position Programmatically

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

问题描述

我在我的应用程序的按钮。我想以编程方式改变其立场。我创建一个XML格式的按钮,如下所示:

I have a button in my application. I want to change its position programmatically. I have created a button in XML as follows:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >

<Button android:text="@+id/Button01" 
        android:id="@+id/Button01" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content"
        android:layout_marginLeft="50px"
        android:layout_marginTop="10px"
        >
</Button>
</LinearLayout>

假如我要设置按钮的位置100像素从左边(如layout_marginLeft =100像素)。我怎样才能做到这一点编程?请帮我解决这个问题。

Suppose I want to set the position of the button as 100px from left (as layout_marginLeft="100px"). How can I do it programmatically? Please help me to solve the problem.

推荐答案

填充和保证金是不一样的...这是线程你在找什么 <一href="http://stackoverflow.com/questions/2481455/set-margins-in-a-linearlayout-programmatically">http://stackoverflow.com/questions/2481455/set-margins-in-a-linearlayout-programmatically

Padding and margin are not the same ... this is thread is what you are looking for http://stackoverflow.com/questions/2481455/set-margins-in-a-linearlayout-programmatically

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

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