Относительный макет, SlidingDrawer и ListView - PullRequest
2 голосов
/ 12 июля 2011

Я пытаюсь построить ListView Activity с помощью панели инструментов вверху. Самым правым инструментом на этой панели инструментов будет обработчик горизонтального SlidingDrawer, который предоставит скользящий EditText поверх других инструментов. Сначала я попытался добиться этого с помощью LinearLayout и FrameLayout, но ползунок занял столько места, сколько было доступно минус общая ширина инструментов. Прямо сейчас я сделал то, что хочу, и отлично работает со следующим макетом:

<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 android: layout_height, чтобы это работало. Если я добавлю «wrap_content», то RelativeLayout заполняет весь экран, и больше ничего не отображается.

Любая помощь по этому вопросу высоко ценится

Заранее спасибо

Ответы [ 3 ]

2 голосов
/ 12 июля 2011

Удалить android:layout_centerVertical="true" из представлений в вашей Относительной компоновке. Я также внес некоторые изменения в ваш слайдер, чтобы получить то, что вы хотите. Основные изменения в ползунке были:

  1. Добавить: android:layout_alignTop="@+id/tool30" и android:layout_alignBottom="@+id/tool30"

  2. Удалить android:layout_alignParentRight="true" и android:layout_centerVertical="true"

Я сделал несколько других косметических изменений в другом месте во время отладки макета.

<?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>
0 голосов
/ 12 июля 2011

Учитывая, что вы определили, что это выдвижной ящик, вы можете захотеть увидеть, имеет ли это обсуждение какое-либо отношение (кажется, вы могли бы использовать информацию)

Высота скольжения

Если бы не я, я бы поискал немного больше с такими критериями.

0 голосов
/ 12 июля 2011

попробуйте окружить RelativeLayout с помощью LinearLayout, в который вы бы поместили:
android:layout_width="wrap_content"<br> android:layout_width="wrap_content
затем измените RelativeLayout с фиксированного объема пространства на fill_parent
другое, что вы можете сделать, это использовать Droid Draw , который позволит вам выложить его визуально.

...