3

这是我的布局,它是一个信息窗口,它显示在有新信息要显示给用户的位置。

布局应该采用一些透明背景颜色和小文本布局的整个屏幕:

<?xml version="1.0" encoding="utf-8"?>
<!-- info fragment - used by the fragment to provide info on a specific fragment -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res/com.coapps.pico"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/background_dark_green" >

    //this is the only layout i see in the result. not it's parent's layout...
    <RelativeLayout
        android:id="@+id/fragment_info_relativelayout_info"
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:layout_alignParentTop="true"
        android:background="@drawable/background_info_window"
        android:clickable="true" >

        <ScrollView
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:layout_centerInParent="true"
            android:layout_margin="5dp" >

            <!-- The info textView -->

            <com.coapps.pico.NillanTextView
                android:id="@+id/fragment_info_textview_info"
                style="@style/text_shadow_black"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_margin="5dp"
                android:gravity="left"
                android:text="Some Text "
                android:textColor="@android:color/white"
                app:isBold="true" />
        </ScrollView>
        <!-- Tap to close -->

        <com.coapps.pico.NillanTextView
            android:id="@+id/fragment_info_textview_tap_to_close"
            style="@style/text_shadow_black"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:gravity="right"
            android:paddingRight="5dp"
            android:text="@string/button_tap_to_close"
            android:textColor="@android:color/white"
            app:isBold="true" />
    </RelativeLayout>

</RelativeLayout>

我正在将此布局添加到另一个 ViewGroup 中,如下所示:

/**
 * Show the info window
 */
public void show()
{
    //if the window is not visible
    if (!isVisible())
        //add window's view
        rootView.addView(infoWindowView);
}

此代码将信息窗口添加到最后一个索引中的根视图容器中。

结果我只看到包含文本的第二个RelativeLayout,但我没有看到它应该是透明的父根布局......

任何想法为什么?

更新: 这是我的容器:

<?xml version="1.0" encoding="utf-8"?>
<!-- This is the main layout of the application -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_basic_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

</RelativeLayout>
4

3 回答 3

0

我也遇到了依赖于相对布局大小的相对布局中的视图问题。我通过更新内部视图大小解决了这个问题

private void update viewSize()
if(rootContainer == null || rootContainer.getLayoutParams() == null)
return;
rootContainer.measure(View.MeasureSpec.makeMeasureSpec(ScalingUtil.getScreenSize().getWidth(), View.MeasureSpec.EXACTLY), View.MeasureSpec.makeMeasureSpec(ViewGroup.LayoutParams.WRAP_CONTENT, View.MeasureSpec.EXACTLY));

    RelativeLayout.LayoutParams oldLayoutParams = (RelativeLayout.LayoutParams) rootContainer.findViewById(R.id.deals_card_center_bg).getLayoutParams();
    RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(rootContainer.getMeasuredWidth(), rootContainer.getMeasuredHeight());
    layoutParams.setMargins(oldLayoutParams.leftMargin, oldLayoutParams.topMargin, oldLayoutParams.rightMargin, oldLayoutParams.bottomMargin);

    rootContainer.findViewById(R.id.deals_card_center_bg).setLayoutParams(layoutParams);
于 2014-01-23T14:27:13.207 回答
0

如何不让父级展开

而不是match_parent在孩子身上,将它与决定高度的兄弟对齐。

<RelativeLayout ...>

    <View
        android:id="@+id/element_that_should_match_its_parents_height"

        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:layout_alignParentTop="true"
        android:layout_alignBottom="@+id/element_that_dictates_height" />

    <View
        android:id="@+id/element_that_dictates_height"

        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

</RelativeLayout>

为我工作,希望它有帮助。第二个View通常是一些ViewGroup,高度不同。

于 2017-03-22T17:07:15.007 回答
-1

尝试改变

<RelativeLayout
        android:id="@+id/fragment_info_relativelayout_info"
        android:layout_width="fill_parent"
        android:layout_height="80dp"
        android:layout_alignParentTop="true"
        android:background="@drawable/background_info_window"
        android:clickable="true" >

<RelativeLayout
        android:id="@+id/fragment_info_relativelayout_info"
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:layout_alignParentTop="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:background="@drawable/background_info_window"
        android:clickable="true" >

无论如何,为什么需要嵌套RelativeLayout

我知道你如何添加视图,所以也试试这个:

infoWindowView.setLayoutParams(
       new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
rootView.addView(infoWindowView);
于 2013-10-17T15:46:22.307 回答