Android的两个按键并排到表行 [英] Android two buttons side by side into table row

查看:206
本文介绍了Android的两个按键并排到表行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个图像和两个按钮的tablelayout。我需要把两个按钮相同行以及相同尺寸in。
现在我能对准同一行中butons但它在diferents大小显示。
背景限定在butons图像而不是大小。
我在code定义图像的属性。
tablelayout的code

 < TableLayout的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
     机器人:ID =@ + ID / tableLayout1
机器人:layout_width =match_parent
机器人:layout_height =match_parent
机器人:背景=@彩色/黑白>
<的TableRow
        机器人:ID =@ + ID / tableRow1
        机器人:layout_width =100dp
        机器人:layout_height =100dp
        机器人:重力=CENTER_HORIZONTAL>
            < ImageView的
                机器人:ID =@ + ID /图像preLOAD
                机器人:layout_width =WRAP_CONTENT
                机器人:layout_height =250dp
                机器人:layout_marginTop =84dp
                机器人:背景=@绘制/ lunafons
                机器人:contentDescription =@字符串/ APP_NAME/>
    < /&的TableRow GT;
    <的TableRow
        机器人:ID =@ + ID / tableRow2
        机器人:layout_width =match_parent
        机器人:layout_height =match_parent
        机器人:重力=CENTER_HORIZONTAL
        机器人:layout_marginTop =50dp
        机器人:layout_gravity =CENTER_HORIZONTAL
        机器人:背景=@彩色/黑白>        <按钮
                机器人:ID =@ + ID / btnload
                机器人:背景=@绘制/ btnback
                机器人:layout_width =match_parent
                 机器人:layout_height =WRAP_CONTENT
                 机器人:layout_weight =1
                />
            <按钮
                机器人:ID =@ + ID / btnload
                机器人:背景=@绘制/ btnloadwallpaper
                机器人:layout_width =match_parent
                 机器人:layout_height =WRAP_CONTENT
                 机器人:layout_weight =1
                />
< /&的TableRow GT;
< / TableLayout>

和背景butons的code:

 <?XML版本=1.0编码=UTF-8&GT?;
<选择
的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android>
<项目的android:state_enabled =假
    机器人:可绘制=@绘制/ btnload1
     /><项目的android:state_enabled =真
    机器人:STATE_ pressed =真
     机器人:可绘制=@绘制/ btnload2
      />
<项目的android:state_enabled =真
    机器人:state_focused =真
    机器人:可绘制=@绘制/ btnload1/>
<项目的android:state_enabled =真
    机器人:可绘制=@绘制/ btnload1/>

感谢


解决方案

 <按钮
        机器人:ID =@ + ID / btnload
        机器人:背景=@绘制/ btnback
        机器人:layout_width =0dp
         机器人:layout_height =WRAP_CONTENT
         机器人:layout_weight =1
        />
    <按钮
        机器人:ID =@ + ID / btnload
        机器人:背景=@绘制/ btnloadwallpaper
        机器人:layout_width =0dp
         机器人:layout_height =WRAP_CONTENT
         机器人:layout_weight =1
        />

因为你正在做的宽度math_parent一段时间,因为你是用体重应该是0dp。

I have a tablelayout with an image and two buttons. I need to put the two buttons in the same row and the same size. Now I could align the butons in the same row but it's shown in diferents size. The background define the image in the butons but not the size. I define the properties of image in the code. The code of tablelayout

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
     android:id="@+id/tableLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/black" > 
<TableRow
        android:id="@+id/tableRow1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:gravity="center_horizontal" >
            <ImageView
                android:id="@+id/imagePreLoad"
                android:layout_width="wrap_content"
                android:layout_height="250dp"
                android:layout_marginTop="84dp"
                android:background="@drawable/lunafons"
                android:contentDescription="@string/app_name" />
    </TableRow>
    <TableRow
        android:id="@+id/tableRow2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center_horizontal"
        android:layout_marginTop="50dp"
        android:layout_gravity="center_horizontal"
        android:background="@color/black" >

        <Button 
                android:id="@+id/btnload"
                android:background="@drawable/btnback"
                android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_weight="1"
                />
            <Button
                android:id="@+id/btnload"
                android:background="@drawable/btnloadwallpaper"
                android:layout_width="match_parent"
                 android:layout_height="wrap_content"
                 android:layout_weight="1"
                />
</TableRow>
</TableLayout>

And the code of background butons:

<?xml version="1.0" encoding="UTF-8"?>
<selector 
xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false"
    android:drawable="@drawable/btnload1"
     />

<item android:state_enabled="true"
    android:state_pressed="true"
     android:drawable="@drawable/btnload2"
      />
<item android:state_enabled="true"
    android:state_focused="true"
    android:drawable="@drawable/btnload1" />
<item android:state_enabled="true"
    android:drawable="@drawable/btnload1" />

Thanks

解决方案

<Button 
        android:id="@+id/btnload"
        android:background="@drawable/btnback"
        android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="1"
        />
    <Button
        android:id="@+id/btnload"
        android:background="@drawable/btnloadwallpaper"
        android:layout_width="0dp"
         android:layout_height="wrap_content"
         android:layout_weight="1"
        />

because you're making the width math_parent while it should be 0dp because you are use weight.

这篇关于Android的两个按键并排到表行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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