将应用程序更改为使用AppCompat后视图消失了 [英] Views gone after changing app to use AppCompat

查看:87
本文介绍了将应用程序更改为使用AppCompat后视图消失了的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以前,我的应用程序根本没有使用AppCompat,但是由于一些需要它的库,现在我需要它.问题是,在我开始使用AppCompat之后,某些Views(ImageViewSeekBar)没有显示:

Previously, my app did not use AppCompat at all, but now I need it due to a few libraries which require it. The problem is, that after I started using AppCompat, some Views (ImageView and SeekBar) are not showing:

发生的变化是,我现在正在使用v7支持库中的AppCompatActivity(而不是Activity)和Theme.AppCompat.Light.DarkActionBar(而不是android:Theme.Holo.Light.DarkActionBar).

What has changed is I am now using AppCompatActivity from v7 support library (instead of Activity) and Theme.AppCompat.Light.DarkActionBar (instead of android:Theme.Holo.Light.DarkActionBar).

布局的层次结构如下:

我知道这很复杂,但这是我能够实现自己想要的唯一方法. (使用了 foreground 框架布局,因此当打开特定的弹出对话框时,我可以使应用程序的其余部分变暗.通过使用多个LinearLayouts可以实现网格.要获得垂直的SeekBar,我需要使用带有SeekBar的FrameLayout里面然后旋转它.红色和蓝色的平铺"实际上是 FButtons )

I know it is quite complex but this was the only way I was able to achieve what I wanted. (The foreground FrameLayout is used so I can dim the rest of the app when a specific popup dialog opens up. Grid is achieved by using multiple LinearLayouts. To get vertical SeekBars I needed to use a FrameLayout with SeekBar inside and then rotate it. The red and blue "tiles" are actually FButtons)

我该如何解决?是由于嵌套的视图过多而导致我看不到ImageButtons和SeekBar的原因吗?

How do I fix this? Is the reason I am not seeing the ImageButtons and SeekBar because of too many nested views?

推荐答案

我可以重现该问题,这很奇怪. 但是,我设法通过将android:elevation="2dp"添加到ImageView的RelativeLayout中来显示ImageViewsSeekBar.我知道这不是解决方案,除了此属性适用于Android API> = 21.

I can reproduce the issue and this is so weird. However I managed to show ImageViews and SeekBar by adding android:elevation="2dp"into the ImageView's RelativeLayout. I know this is not a solution, besides this attribute is for Android API >= 21.

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:elevation="2dp">
        // ImageViews and SeekBar here
        ...
</RelativeLayout>


另一个解决方法,但可以在API 21之前和更高版本中运行. 在模拟器API 18上进行了测试.


Another workaround but works prior and above API 21. Tested on emulator API 18.

将其放入您的 value/styles.xml :

Put this in your value/styles.xml:

<style name="my_style">
    // let this empty
</style>

将其放入您的 value-v21/styles.xml :

Put this in your value-v21/styles.xml:

<style name="my_style">
    <item name="android:elevation">5dp</item> // above 2dp apparently...
</style>

并将style="@style/my_style"添加到每个 RelativeLayout我在第一个答案中提到的内容.

And add style="@style/my_style"to each RelativeLayout I was talking about in first answer.

<RelativeLayout
    style="@style/my_style"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
        // ImageViews and SeekBar here
        ...
</RelativeLayout>

在深入研究的同时,我发现了.

While digging a little more, I found this.

这篇关于将应用程序更改为使用AppCompat后视图消失了的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆