【发布时间】:2011-07-12 17:08:54
【问题描述】:
我正在尝试构建一个顶部带有工具栏的 ListView 活动。此工具栏中最右边的工具将是水平 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 会填满整个屏幕,并且不会显示其他任何内容。
非常感谢您对此的任何帮助
提前谢谢你
【问题讨论】:
-
这很奇怪,我怀疑其中一个孩子的身高导致了问题,但在我看来他们都还不错。有时相对的布局会导致意想不到的后果。您是否尝试过使用空的相对布局(工具栏)或者我猜只有一个孩子,否则它的高度将为零
-
我试过了,wrap_content 值按预期工作。所以我要一次放一个元素,看看哪里出错了。谢谢
-
好的,当我添加 SlidingDrawer 时,RelativeLayout 开始乱七八糟。我真的被困在这里了......
-
我希望您可以添加图像,以便我可以看到抽屉的外观,但是您可以将抽屉的高度设置为您使用的任何可绘制对象吗?
标签: android android-relativelayout slidingdrawer