【问题标题】:Make LinearLayout in FrameLayout opaque使 FrameLayout 中的 LinearLayout 不透明
【发布时间】:2015-03-25 20:54:38
【问题描述】:

我找不到如何使 linearLayout 不透明的方法。无论我做什么,它总是透明的。

布局如下:

<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>

如何使 LinearLayout 不透明?也许我可以尝试使用实体可绘制对象来代替仅设置颜色..?

背景

我正在使用 appcompat v7 主题&lt;style name="AppTheme" parent="Theme.AppCompat.NoActionBar"&gt;

我尝试过的事情

  1. 覆盖主题的面板背景从透明到&lt;item name="android:panelBackground"&gt;@android:color/black&lt;/item&gt;
  2. 在 LinearLayout 上将背景设置为 background=#FF000000
  3. 在 LinearLayout 上将 alpha 设置为 alpha=1
  4. 将背景设置为可绘制android:background="@drawable/background_error_panel",其中可绘制对象是:

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

2015 年 3 月 25 日编辑

也许动画是问题..?我使用缩放动画和代码:

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);
    }


}

【问题讨论】:

  • 你能给出gray_background_dark的定义吗?
  • 我已将其替换为实际值 (#FF181818)。
  • 我认为问题在于 FrameLayout 使视图变得透明...
  • 只是一个随机的想法:尝试将线性布局的背景设置为@android:color/black,将滚动视图的背景设置为@android:color/white - 那么你会得到什么?
  • 尝试切换error_panel和ScrollView。

标签: android android-linearlayout android-xml android-framelayout


【解决方案1】:

这是你的 ScrollView 是透明的。根据docs

子视图在堆栈中绘制,最近添加的子视图在顶部。

所以你需要先加载 ScrollView 才能让它在后台运行。

【讨论】:

  • 我知道这个答案已被接受,但我不太明白。如果 ScrollView 在上面并且有透明背景,那么下面的 LinearLayout 的不透明背景不应该已经通过它可见了吗?
  • @ci_ 是的,如果它真的不透明的话。我认为 OP 只是试图使该背景 透明 (默认情况下它已经是)并且从未为其分配颜色。
  • 好吧,不——你是对的,它应该有。也许 OP 一直看到 ScrollView 文本。
  • 是的,可能就是这样,也许问题中有一些误导性陈述。无论如何没关系,他很高兴它已经解决了,我得到确认我不会发疯。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-11-01
  • 1970-01-01
  • 2016-04-15
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多