简体   繁体   中英

Layout not displaying correctly

A strange thing is happening, I have the exactly same activities, but in one of them, the buttons in the layout appear out of bounds if I add the following code:

getSupportActionBar().setDisplayHomeAsUpEnabled(true);

I have this code in others activities as well but only in this one this error occurs. And it only occurs on some android versions, from 4.4 to 6.0 works fine. Yes, I've checked, if I remove this line from the code, it works perfectly, but if add it back my buttons appear out of bounds, and it's only the left button. 布局错误

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.mimica);

    Toolbar toolbar = findViewById(R.id.Toolbar);
    setSupportActionBar(toolbar);
    getSupportActionBar().setDisplayHomeAsUpEnabled(true);
    getSupportActionBar().setDisplayShowHomeEnabled(true);
}

Any idea why this is happening?

You need to play with gravity and layout_gravity,

android:gravity : It sets the gravity of the contents (ie it's sub views) of the View it's used on. android:layout_gravity : It sets the gravity of the View or Layout relative to its parent.

您是否检查过XML文件是否良好?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM