Android的 - 如何分成4等份一个看法? [英] Android - How to split a view in 4 equal parts?

查看:785
本文介绍了Android的 - 如何分成4等份一个看法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想借此画面,将其划分为四个正方形以不同的颜色 并附加一个点击监听器给他们。

I'd like to take a screen, divide it to four squares in different colors and attach a click listener to them.

我的问题是我怎么分割屏幕4相等的正方形。

My question is how do I split the screen to 4 equal squares.

在此先感谢!

Dvir

推荐答案

下面是4个按钮用不同颜色的布局:

Here is a layout with 4 buttons with different colors:

<?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="match_parent"
android:orientation="vertical" >

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1.0"

    android:orientation="horizontal" >

    <Button
        android:id="@+id/button1"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/white"
        android:layout_weight="1.0"
        android:text="Button" />

    <Button
        android:id="@+id/button2"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_green_light"
        android:layout_weight="1.0"
        android:text="Button" />

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_weight="1.0"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/button3"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_blue_light"
        android:layout_weight="1.0"
        android:text="Button" />

    <Button
        android:id="@+id/button4"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@android:color/holo_red_light"
        android:layout_weight="1.0"
        android:text="Button" />

</LinearLayout>
</LinearLayout>

这篇关于Android的 - 如何分成4等份一个看法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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