Android Studio changing ID's in one xml file changes the ID's in another file

前端 未结 3 1581
刺人心
刺人心 2021-02-13 03:10

I used to give simple ids to Android Views, but lately, I stopped that altogether because of this issue.

Let\'s say I have 2 layouts, one named first_layout.xml

3条回答
  •  孤独总比滥情好
    2021-02-13 04:17

    I just came across this post because I was having a similar problem. I have an app with different flavors. In one of my layouts I have 12 buttons. In a different flavor, I want all of those buttons plus I add 4 more. So, I created a new version of the layout in a flavor-specific directory. The problem is every time I tried to change anything that has an ID it would change the identically-named layout in the main directory.

    With flavors, you're supposed to be able to override the main directory's layout with a flavor specific one. This was extremely frustrating!

    This MUST be a bug in Android Studio. The frustrating part is that it's still not fixed. I installed Android Studio via the JetBrains toolbox since I use other JetBrains IDEs. Currently I'm on version 3.5.3

    My workaround

    To get around this bug I created a "test" project. I copied the layout code that I wanted to modify, pasted it in the test project and edited it there. When I was done altering it the way I wanted, I created the alternative layout in the flavor specific directory (using the same name as the main directory's layout that I want to override) of the actual project I was working on. Then I copied the layout from my test project and pasted it into the flavor specific file. By doing this, it didn't alter the layout in the project's main directory.

    My thoughts

    You shouldn't have to do this. It's certainly not the intuitive way. This is why I can't believe that this is anything but a bug. With that said, I hope I have provided a clear workaround for anyone else who's stuck. If I haven't comment below and I will clarify what I can.

提交回复
热议问题