我找不到如何使 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主题<style name="AppTheme" parent="Theme.AppCompat.NoActionBar">
我尝试过的事情
- 将主题的 panelBackground 从透明覆盖为
<item name="android:panelBackground">@android:color/black</item>
- 将背景设置为
background=#FF000000
在 LinearLayout 上。 - 将 alpha 设置为
alpha=1
在 LinearLayout 上。 将背景设置为可绘制
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/