Asked  6 Months ago    Answers:  5   Viewed   54 times

How can I have one layout for landscape and one for portrait? I want to assume extra width and conserve vertical space when the user rotates the phone over sideways.



By default, the layouts in /res/layout are applied to both portrait and landscape.

If you have for example


you can add a new folder /res/layout-land, copy main.xml into it and make the needed adjustments.


See also and for some more options.

Tuesday, June 1, 2021
answered 6 Months ago

The inflate exception is not actually the problem but really comes from another deeper issue in your layout that is then wrapped in an InflateException. A common issue is an out of memory exception when trying to inflate an ImageView loading a drawable resource. If one of these resources has a high pixel resolution it would take a lot of memory causing then an inflate exception.

So basically verify that the pixel resolution in all your image drawables is just the minimum necessary for your layout.

Tuesday, June 1, 2021
answered 6 Months ago

Don't worry . . .

I got the same problem before .Use my way to get drawable

 Drawable image = c.getResources().getDrawable(R.drawable.name_of_image_in_drawableFolder);

example :

Drawable image = c.getResources().getDrawable(R.drawable.ic_launcher);

This will definetely solove your problem.

But, If you dont have images in drawable folder There might be two posibilities

- Getting Drawable from Phone(SDCARD)
- Getting Drawable from url

In First Case


In Second case

    public Drawable drawableFromUrl(String url) throws IOException {
        Bitmap x;
        HttpURLConnection connection = (HttpURLConnection) new URL(url)
        InputStream input = connection.getInputStream();
        x = BitmapFactory.decodeStream(input);
        return new BitmapDrawable(x);

Reference :Android Drawable Images from URL

If any problem persists you can contact me .

Monday, August 16, 2021
Chris Herrera
answered 4 Months ago

It's possible now with the Data Binding Library.

First, you have to define a variable for the BuildConfig object:

  <import type="android.view.View" />


Then just use it like this:

  android:visibility="@{buildConfig.DEBUG ? View.VISIBLE : View.GONE}">
Saturday, October 16, 2021
answered 2 Months ago

You can use a SuperClass for activities and implement this on, for example, onCreate().

Wednesday, November 3, 2021
answered 4 Weeks ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :