我的屏幕上有一些弹出窗口,需要的东西不那么常见。查看另一个视图
我将带有Header + Content + Footer的弹出窗口布局为LinearLayout。但我需要一个小箭头才能显示在我的组件上。
当弹出窗口位于锚点上方并且箭头向下时,我使用下面的代码来绘制它。
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/content" android:orientation="vertical"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:id="@+id/header" android:background="@drawable/background_header"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="wrap_content">
</LinearLayout>
<HorizontalScrollView android:background="@drawable/background"
android:layout_width="wrap_content" android:layout_height="match_parent"
android:scrollbars="none">
</HorizontalScrollView>
<ImageView android:id="@+id/arrow_down" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_marginTop="-3dip"
android:src="@drawable/quickcontact_arrow_down" />
</LinearLayout>
在运行时,我能够把箭头正好与下面的代码锚以上。
ViewGroup.MarginLayoutParams param = (ViewGroup.MarginLayoutParams) mArrowDown
.getLayoutParams();
param.leftMargin = root.getMeasuredWidth()
- (screenWidth - anchor.getLeft());
它显示正确。
现在我需要做同样的事情,但箭头需要显示在上方。 我的问题是箭头需要在另一个视图上重叠一点(导致背景色匹配它们),所以这就是为什么它需要在后面绘制。
我试着用FrameLayout让“内容”有一些topMargin,但它不工作。
我知道这可以用AbsoluteLayout来完成,但我不惜一切代价避免它。
编辑:
以下Josh答案,我写了下面的代码。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="wrap_content">
<LinearLayout android:id="@+id/content"
android:orientation="vertical" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:fadingEdgeLength="0dip">
<RelativeLayout android:id="@+id/header"
android:background="@drawable/background_header" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="wrap_content">
</RelativeLayout>
<HorizontalScrollView android:background="@drawable/background"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:scrollbars="none">
</HorizontalScrollView>
</LinearLayout>
<ImageView android:id="@+id/arrow_up" android:layout_above="@id/content"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:src="@drawable/quickcontact_arrow_up" />
</RelativeLayout>
但我不知道为什么,箭头现在不显示。
我知道,这是一个很强烈的代码。我要测试你的解决方案。 – 2011-05-02 15:40:47
指出@Josh,我同意你的看法,'RelativeLayout'肯定能解决问题。 +1为紧凑desc。的解决方案。 – rekaszeru 2011-05-02 15:47:35
好吧,我试着按照你的解决方案,但箭头现在不出现。我添加了代码,我在我的问题上尝试。 – 2011-05-02 15:57:02