相对布局,SlidingDrawer和ListView布局、SlidingDrawer、ListView

2023-09-06 05:01:25 作者:昂贵的点缀。

我想建立一个ListView活动在顶部的工具栏。此工具栏最右边的工具将是一个处理程序,以一个水平SlidingDrawer这将提供一个滑动的EditText上的其他工具顶部。首先,我试着用的LinearLayout和的FrameLayout来实现这一点,但滑去不亚于工具总宽度是可用减去空间。现在,我已经做了我想要的东西,并与以下布局的伟大工程:

I am trying to build a ListView Activity with a toolbar at the top. The rightmost tool in this toolbar will be a handler to a horizontal SlidingDrawer which will provide a sliding EditText on top of the other tools. First I tried to achieve this with LinearLayout and FrameLayout but the slider went as much as the space that was available minus the tools total width. Right now I have done what I want and works great with the following layout:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout android:id="@+id/laytoptoolbarhost"
    android:layout_width="fill_parent"
    android:layout_height="55dip"
    android:background="@drawable/toptoolbar_gradient"
    android:padding="5dip">
    <View android:id="@+id/tool10"
        android:layout_width="32dip"
        android:layout_height="32dip"
        android:paddingRight="3dip"
        android:background="#00FF00"
        android:layout_alignParentLeft="true"
        android:layout_centerVertical="true">
    </View>     
    <View android:id="@+id/tool20"
        android:layout_width="32dip"
        android:layout_height="32dip"
        android:paddingRight="3dip"
        android:background="#00FF00"
        android:layout_toRightOf="@+id/tool10"
        android:layout_centerVertical="true">
    </View>
    <View android:id="@+id/tool30"
        android:layout_width="32dip"
        android:layout_height="32dip"
        android:paddingRight="3dip"
        android:background="#00FF00"
        android:layout_toRightOf="@+id/tool20"
        android:layout_centerVertical="true">
    </View>             
    <SlidingDrawer android:id="@+id/slidesearch"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:layout_alignParentRight="true"
        android:layout_centerVertical="true"
        android:handle="@+id/sliderhandle"
        android:content="@+id/txtsearch">
        <ImageView android:id="@+id/sliderhandle"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/btn_collapse_states">
        </ImageView>
        <EditText android:id="@+id/txtsearch"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:textSize="20sp">
        </EditText>
    </SlidingDrawer>
</RelativeLayout>
<ListView android:id="@id/android:list"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:layout_weight="1"
           android:drawSelectorOnTop="false"/>
 <TextView android:id="@id/android:empty"
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           android:gravity="center"
           android:textSize="20sp"
           android:text="@string/lbl_norecords"/>    

问题是,我必须把在RelativeLayout的机器人固定值:layout_height参数为了这个工作。如果我把WRAP_CONTENT,那么RelativeLayout的填满整个屏幕,并没有做任何显示。

The problem is that I have to put a fixed value in RelativeLayout android:layout_height parameter in order for this to work. If I place "wrap_content" then the RelativeLayout fills the entire screen and nothing else is showing.

任何帮助是非常AP preciated

Any help on this is highly appreciated

感谢您提前

推荐答案

删除的android:layout_centerVertical =真正的从您的相对布局的意见。我也做了一些更改滑块以得到你想要的东西。滑块的关键变化是:

Remove android:layout_centerVertical="true" from the views in your Relative Layout. I also made some changes to your slider to get to what you want. The crucial changes to the slider were:

地址:的android:layout_alignTop =@ + ID / tool30的android:layout_alignBottom =@ + ID / tool30

删除的android:layout_alignParentRight =真正的和    的android:layout_centerVertical =真正的

我在其他地方做了一些其他化妆品的变化,而调试的布局。

I made a few other cosmetic changes elsewhere while debugging the layout.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent">
    <RelativeLayout
        android:id="@+id/laytoptoolbarhost"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:padding="5dip"
        android:layout_weight="0">
        <View
            android:id="@+id/tool10"
            android:layout_width="32dip"
            android:layout_height="32dip"
            android:paddingRight="3dip"
            android:background="#00FF00"
            android:layout_alignParentLeft="true"
            >
        </View>
        <View
            android:id="@+id/tool20"
            android:layout_width="32dip"
            android:layout_height="32dip"
            android:paddingRight="3dip"
            android:background="#FFFF00"
            android:layout_toRightOf="@+id/tool10"
            >
        </View>
        <View
            android:id="@+id/tool30"
            android:layout_width="32dip"
            android:layout_height="32dip"
            android:paddingRight="3dip"
            android:background="#00FFFF"
            android:layout_toRightOf="@+id/tool20"
            >
        </View>
        <SlidingDrawer
            android:id="@+id/slidesearch"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:layout_alignTop="@+id/tool30"
            android:layout_alignBottom="@+id/tool30"
            android:handle="@+id/sliderhandle"
            android:content="@+id/txtsearch">
            <ImageView
                android:id="@+id/sliderhandle"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:src="@drawable/alarm_clock">
            </ImageView>
            <EditText
                android:id="@+id/txtsearch"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:textSize="20sp">
            </EditText>
        </SlidingDrawer>
    </RelativeLayout>
    <ListView
        android:id="@id/android:list"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:drawSelectorOnTop="false" />
    <TextView
        android:id="@id/android:empty"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:gravity="center"
        android:textSize="20sp"
        android:text="nothing" 
        />
</LinearLayout>
 
精彩推荐
图片推荐