android - 使FrameLayout中的LinearLayout不透明

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

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

enter image description here

布局如下:

<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主题<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">

我尝试过的事情

  1. 将主题的 panelBackground 从透明覆盖为 <item name="android:panelBackground">@android:color/black</item>
  2. 将背景设置为 background=#FF000000在 LinearLayout 上。
  3. 将 alpha 设置为 alpha=1在 LinearLayout 上。
  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);
    }


}

最佳答案

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

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

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

关于android - 使FrameLayout中的LinearLayout不透明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29266322/

相关文章:

android - 如何将 View 作为背景添加到 surfaceView?

android - 如何缩放按钮内的可绘制对象,以便按钮大小不受可绘制对象的控制?

安卓 : How to put cross icon on top of the autocomplete textView

android - 一个linearLayout里面的两个tableLayout

当我尝试创建可绘制资源文件时,Android Studio 出现奇怪的错误

android - EditText - 文本和 EditText 行之间的间隙

java - java.net.SocketTimeoutException 中 "Connect timed out"和 "failed to connect to"之间的确切区别是什么?

java - 如何将一项 Activity 实现到另一项 Activity 中?

android - Android 中两个 View 的垂直中心对齐

android - 如何自动应用父级的样式?