简体   繁体   中英

Android XML Layout using buttons

I want to add two buttons in a single linear layout with horizontal orientation, I want my buttons to be stretched if the screen is bigger and contracted if the screen is small, what should I do to keep those exactly the same size together?

Fill parent or match parent causes only one to be displayed on the screen, what should be done to make both of them visible at the same time on any screen size?

give both of them the following properties :

weight =1
layout_width=fill_parent

here is a working code

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

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button 1" >
    </Button>

    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button 2" >
    </Button>

</LinearLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM