Android的设置按钮宽度的一半屏幕 [英] Android setting Button width half the screen

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

问题描述

如何设置(XML格式),该按钮将屏幕宽度的一半。我发现只有包的内容,匹配父(填充整个屏幕)和DP如确切数额:50dp。
如何设置它究竟是按住屏幕?

How to setup(in XML) that the button will have width half of screen. I found only wrap content, match parent(fills whole screen) and exact amount of dp eg: 50dp. How to set it exactly hold the screen?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
 android:weightSum="2"
>

 <Button
     android:id="@+id/buttonCollect"
     android:layout_width="match_parent"
     android:layout_height="wrap_content"
     android:layout_weight="1"
     android:paddingLeft="8dp"
     android:paddingRight="8dp"
     android:text="przycisk" />

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

推荐答案

这可以通过让你的布局两个小部件来完成:
使用的LinearLayout并设置 layout_width =FILL_PARENT在两个部件(按钮和另一小窗口),并设置layout_weight也为相同的值。
而将的LinearLayout平分在两个部件之间的宽度和你的按钮将占据半壁江山的画面。

This can be done by having two widgets on your layout: use a LinearLayout and set layout_width="fill_parent" on both widgets (Button and another widget ), and set layout_weight also to the same value . and the LinearLayout will split the width between the two widget equally and your button will occupy half of the screen.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:orientation="horizontal">

 <Button
     android:id="@+id/buttonCollect"
     android:layout_width="fill_parent"
     android:layout_height="wrap_content"
     android:layout_weight="1"
     android:paddingLeft="8dp"
     android:paddingRight="8dp"
     android:text="przycisk" />

<Button
    android:id="@+id/button2"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:layout_alignParentBottom="true"
    android:layout_alignParentRight="true"
    android:text="Button" />

这篇关于Android的设置按钮宽度的一半屏幕的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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