从右到左增加Android按钮的宽度 [英] Increase Android button's width from right to left

查看:68
本文介绍了从右到左增加Android按钮的宽度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望按钮宽度从右向左增加,而不是从左向右增加,该怎么办?

I want button width to be increased from right to left, and not from left to right , what should I do?

例如:

Button btn = findviewbyId(R.id.Button1);
btn.setwidth(1000);

这将从按钮的右侧开始增加宽度,但是我希望它沿相反的方向增加.

This will start increasing width from right side of button, but I want it to increase in the opposite direction.

推荐答案

尝试一下

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="end"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.example.btns.MainActivity" >

<TextView
    android:id="@+id/textView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="@string/hello_world" />

<Button
    android:id="@+id/button1"
    android:layout_width="wrap_content"
    android:layout_height="66dp"
    android:gravity="end"
    android:text="Button" />

<Button
    android:id="@+id/button2"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Button" />

public class MainActivity extends ActionBarActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);


    final Button btn=(Button) findViewById(R.id.button2);
    btn.setOnClickListener(new View.OnClickListener() {

        int i=0;
        @Override
        public void onClick(View arg0) {

            i=i+50;

            btn.setWidth(i);

            p(i);

        }
        private void p(int i) {

            System.out.println(i);

        }
    });

}}

这篇关于从右到左增加Android按钮的宽度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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