我有一个EditText ,三个按钮,要横向布局,三个按钮在右边,edittext在左边,要占慢整行,且要适宜各种分辨率怎么写代码

解决方案 »

  1.   

    那按钮的大小,editText的长度怎么设
      

  2.   

    我下面用的是3个TextView,设置它的cliable = true,同样有点击事件,由于用Button的话,3个堆起来高度比较难看,你可以试试看,是不是需要这个
    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:gravity="center_vertical">
      <EditText android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight = "1"
      ></EditText>
      <LinearLayout android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation = "vertical"
                    android:layout_weight = "2"
                    android:clickable="true"
                    android:gravity="center"
                    >
            <TextView android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text = "Button1"
                    android:clickable="true"
                    android:gravity="center"
            ></TextView>
           <TextView android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text = "Button1"
                    android:clickable="true"
                    android:gravity="center"
            ></TextView>
            <TextView android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text = "Button1"
                    android:clickable="true"
                    android:gravity="center"
            ></TextView>
      </LinearLayout>
    </LinearLayout>
      

  3.   

    Jason_WKS
    谢谢你的回答,可我要用按钮,按钮式横排的,在EditText后面
      

  4.   

    借楼主宝地一用,大侠们看看我的问题吧  困扰N久了 真的要疯了,楼主见谅http://topic.csdn.net/u/20110827/14/65a541fd-0003-48ef-9643-aaf9ba6f73aa.html?seed=2110419927&r=75193022#r_75193022
      

  5.   

    LayoutParams layoutParams = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);
    button.setLayoutParams(layoutParams);  ORbutton.setHeight(pixels)
    button.setWidth(pixels)
    不晓得是你想要的不
      

  6.   

    我在eclipse中怎么没有这两个方法呢
    button.setHeight(pixels)
    button.setWidth(pixels)
    我是现在XML文件中定义,然后再代码中就没这两个方法
      

  7.   

    包是引用的这个啥  import android.widget.Button;
      

  8.   

    button.setMaxWidth(maxWidth)
    这个呢
      

  9.   

    我刚刚试了,只有在代码中定义Button才有setWidth()方法,如果在xml中定义然后再代码中引用就只有setMaxWidth()
      

  10.   

    可以使用多个分辨率的layout文件进行控制,png背景可以用9-patch图片。
      

  11.   

    要自适应还是用wrap_content 和 match_parent.将原来的略微改动下就好,layout_weight属性的意思,如果不懂,请参照:http://blog.csdn.net/jason_wks/article/details/6663158<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:gravity="center_vertical">
      <EditText android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight = "1"
      ></EditText>
      <LinearLayout android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation = "horizontal"
                    android:layout_weight = "1"
                    android:gravity="center"
                    android:layout_margin="3px"
                    >
           <Button android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text = "B1"
                    android:clickable="true"
                    android:gravity="center"
                    android:layout_margin="3px"
                    android:layout_weight = "1"
            ></Button>
           <Button android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text = "B2"
                    android:clickable="true"
                    android:gravity="center"
                    android:layout_margin="3px"
                    android:layout_weight = "1"
            ></Button>
            <Button android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:text = "B3"
                    android:clickable="true"
                    android:gravity="center"
                    android:layout_margin="3px"
                    android:layout_weight = "1"
            ></Button>
      </LinearLayout>
    </LinearLayout>在这之中,Button内文字与边框间的空白太大,显得不大好看