0

Android中线性布局和权重的可能重复

你好,

我有奇怪的问题。我设计了一个自定义小部件,它具有三个按钮的线性布局。它的代码是这样的:

<?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:weightSum="3" >

    <ToggleButton
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/tbBrowse"
        android:background="@drawable/btn_tg_browse"
        android:textOn=""
        android:textOff=""
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:checked="false"
        android:gravity="bottom"/>

    <ToggleButton
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/tbHotSpot"
        android:background="@drawable/btn_tg_hotspot"
        android:textOn=""
        android:textOff=""
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:checked="true"
        android:gravity="bottom"/>

    <ToggleButton
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/tbMatches"
        android:background="@drawable/btn_tg_matches"
        android:textOn=""
        android:textOff=""
        android:focusable="false"
        android:focusableInTouchMode="false"
        android:checked="false"
        android:gravity="bottom"/>

</LinearLayout>

它的外观和感觉是这样的,看起来还不错:

在此处输入图像描述

我已将此小部件添加到我的班级(android:id="@+id/Footer"):

<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/White">

    <view
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        class="com.belldigital.widget.HeaderBar"
        android:id="@+id/Header"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" />

    <view
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        class="com.belldigital.widget.FooterBar"
        android:id="@+id/Footer"
        android:layout_alignParentBottom="true" />

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_below="@id/Header"
        android:layout_above="@id/Footer"/>


</RelativeLayout>

因为,在“视图”声明中没有定义重力,我希望看到与第一张图像相同的外观和感觉,但我在模拟器和真实设备中都看到了下面的图像。

在此处输入图像描述

你认为呢?如果我基于相对布局重新设计我的小部件可能没问题。但是,我认为当前的设计还可以,但为什么“视图”小部件会扰乱我的排列?任何评论/建议将不胜感激。

4

1 回答 1

0

我将上面的“视图”更改为跟随然后我的问题神奇地解决了:)

<view
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        class="com.belldigital.widget.FooterBar"
        android:id="@+id/Footer"
        android:layout_alignParentBottom="true"
        android:orientation="vertical"/>
于 2013-04-08T06:37:30.907 回答