Reputation: 3137
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"/>
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.
Any help on this is highly appreciated
Thank you in advance
Upvotes: 2
Views: 4007
Reputation: 8391
try surrounding the RelativeLayout with a LinearLayout in which you would put:
android:layout_width="wrap_content"
android:layout_width="wrap_content
then change the RelativeLayout from a fixed amount of space, to fill_parent
the other thing you can do is to use Droid Draw which will allow you to lay it out visually.
Upvotes: 0
Reputation: 2988
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:
Add: android:layout_alignTop="@+id/tool30"
and android:layout_alignBottom="@+id/tool30"
Remove android:layout_alignParentRight="true"
and
android:layout_centerVertical="true"
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>
Upvotes: 2
Reputation: 6311
Given that you have determined that it's the sliding drawer you may want to see if this discussion has any bearing (seems like you might be able to use the info)
If not I would search a bit more with that type of criteria.
Upvotes: 0