Make LinearLayout in FrameLayout opaque

半腔热情 提交于 2019-12-11 02:17:19

问题


I cannot find a way how to make linearLayout opaque. It's always transparent no matter what I do.

The layout looks like this:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent">

  <LinearLayout
    android:orientation="vertical"
    android:id="@+id/error_panel"
    android:layout_width="match_parent"
    android:background="@color/gray_background_dark"
    android:layout_height="wrap_content">

      <TextView
        android:id="@+id/error_message"
        android:text="@string/dummy_number"
        android:gravity="center_vertical|left"
        android:textColor="@color/red"
        android:layout_width="match_parent"
        android:layout_marginTop="5dp"
        android:layout_marginBottom="5dp"
        android:layout_marginLeft="@dimen/activity_horizontal_margin"
        android:layout_marginRight="@dimen/activity_horizontal_margin"
        android:layout_height="wrap_content" />

  </LinearLayout>

  <!-- The content of this scroll view is seen underneath the errorPanel -->
  <ScrollView
    android:layout_height="match_parent"
    android:layout_width="match_parent">

      <!-- Content of ScrollView -->

  </ScrollView>
</FrameLayout>

How can I make the LinearLayout opaque? Maybe instead of setting just color I could try to use a solid drawable..?

Background

I am using appcompat v7 theme <style name="AppTheme" parent="Theme.AppCompat.NoActionBar">

Things I tried

  1. Override the theme's panelBackground from transparent to <item name="android:panelBackground">@android:color/black</item>
  2. Set background as background=#FF000000 on LinearLayout.
  3. Set alpha as alpha=1 on LinearLayout.
  4. Set background as drawable android:background="@drawable/background_error_panel" where the drawable is:

    <shape xmlns:android="http://schemas.android.com/apk/res/android"
    android:shape="rectangle" >
    
        <solid android:color="#FF181818"/>
    
    </shape>
    

Edit 3/25/2015

Maybe the animations are the problem..? i use scale anims and in code:

public void toggle() {
    panel.setText("Some text  Some text Some text Some text Some text ");
    Animation slideIn = AnimationUtils.loadAnimation(MyApplication.context, R.anim.slide_in);
    Animation slideOut = AnimationUtils.loadAnimation(MyApplication.context, R.anim.slide_out);

    if (layout.getVisibility() == View.GONE) {
        layout.setVisibility(View.VISIBLE);
        layout.startAnimation(slideIn);
        layout.setAlpha(1);
    } else {
        layout.startAnimation(slideOut);
        layout.setVisibility(View.GONE);
    }


}

回答1:


It is your ScrollView being transparent. As per the docs,

Child views are drawn in a stack, with the most recently added child on top.

So you need to load the ScrollView first to have it in the background.



来源:https://stackoverflow.com/questions/29266322/make-linearlayout-in-framelayout-opaque

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!