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