2

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:

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

The hieararchy of the layout is as follows:

A frame layout contains a relative layout. The relative layout contains two images and another frame layout that has a seek bar. The relative layout is what goes missing.

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)

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

BSMP
  • 3,862
  • 8
  • 31
  • 41
Primož Kralj
  • 5,534
  • 14
  • 65
  • 125
  • Could you add (or link to) your entire layout xml? I'd like to be able to try to duplicate the problem in my own IDE. – Ben P. Sep 18 '17 at 22:05
  • Sure: [activity_main.xml](https://expirebox.com/download/8b61e0a0b24ab1cd6a72f8f04e421d4d.html) – Primož Kralj Sep 18 '17 at 22:11
  • @PrimožKralj In the future, please edit your question to include the relevant parts of the layout instead of providing a download link to it in a comment. Took a look at your XML and the `ImageViews` have their `visibility` set to `gone`. Do you change them from code? – Gergely Kőrössy Sep 18 '17 at 22:52
  • Yes, the visibility of `ImageView`s is controlled programaticaly. – Primož Kralj Sep 18 '17 at 22:54

1 Answers1

3

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>


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

Put this in your value/styles.xml:

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

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

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

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.

BSMP
  • 3,862
  • 8
  • 31
  • 41
Punchlag
  • 208
  • 1
  • 6
  • Well, this is encouraging, thanks. I would still need a solution for API < 21 though. – Primož Kralj Sep 19 '17 at 14:06
  • I appreciate your effort but it's still not perfect. When the `FButton` is in a pressed state the `RelativeLayout` (containing ImageViews and SeekBar) dissapears (and reappears as soon as it's not pressed anymore). – Primož Kralj Sep 19 '17 at 21:23
  • @PrimožKralj I think that Punchlag is on the track to solving your issue. It definitely looks like an elevation problem. For instance, in the emulator, if I display with API 20 or below, I see your vanished items. With API 21+, I don't. Setting elevation on the RelativeLayout solves it. You may have an additional issue with button animation. Take a look at [this posting](https://stackoverflow.com/questions/27080338/android-5-0-androidelevation-works-for-view-but-not-button) to see if this is related to your problem. – Cheticamp Sep 21 '17 at 00:25
  • @PrimožKralj You do also seem to be running into a feature implemented in API 21: [StateListAnimator](https://developer.android.com/reference/android/animation/StateListAnimator.html). Either set `android:stateListAnimator="@null"` or set elevation high enough to overcome whatever `StateListAnimator` is doing. (6dp seems high enough). – Cheticamp Sep 21 '17 at 12:15
  • Solved. The elevation I had was 5dp, that's why it wasn't working. After setting it to 6dp, it works. Also, as @Cheticamp wrote, adding `android:stateListAnimator="@null"` to `FButton` works too. Thanks guys – Primož Kralj Sep 21 '17 at 14:01