Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9216509
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T02:25:58+00:00 2026-06-18T02:25:58+00:00

My app has three views in portrait mode, a TextSwitcher, a custom view and

  • 0

My app has three views in portrait mode, a TextSwitcher, a custom view and a custom keyboard.
In the landscape mode I need to remove the TextSwitcher and add a ListView in the right side.
I am new to android , I can define two layouts namely xxx and xxx-land, my problem is how to implement two branch of code, one for controling landscape and one for portrait.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T02:25:59+00:00Added an answer on June 18, 2026 at 2:25 am

    define all Views that appears in both resource file in you code
    and in the onCreate() in the Activity you can check the orientation to bind the Views to your class object .

    example.

    here we have 2 layout files that contain an ImageView in both files and in the portrait file there is an TextView and in the landscape it contain a Button instead of the TextView

    my_layout.xml in layout-land

        <Button
            android:id="@+id/button1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Button" />
    
        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/abs__ab_bottom_solid_dark_holo" />
    
    </LinearLayout>
    

    my_layout.xml in layout-port folder

        <ImageView
            android:id="@+id/imageView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/abs__ab_bottom_solid_dark_holo" />
    
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="TextView" />
    
    </LinearLayout>
    

    here is the Activity code

    package com.example.stackoverflow;
    
    import android.app.Activity;
    import android.content.res.Configuration;
    import android.os.Bundle;
    import android.view.Display;
    import android.widget.Button;
    import android.widget.ImageView;
    import android.widget.TextView;
    
    public class MyActivity extends Activity {
    
        // landscape views
        Button button1;
    
        // protrati views
        TextView textView1;
    
        // common views (shared between landscape and protrait mode)
    
        ImageView imageView1;
    
        public MyActivity() {
            // TODO Auto-generated constructor stub
        }
    
        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
    
            setContentView(R.layout.my_layout);
            imageView1 =(ImageView) findViewById(R.id.imageView1);//exist inside landscape file and portrait
    
    
            if(getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT){
                textView1 = (TextView)findViewById(R.id.textView1);
            }else{
                button1 = (Button) findViewById(R.id.button1);
            }
    
    
            //when you want to access any thing that is not shared 
            //check the orientation 
    
    
    
    
        }
    
    
        @Override
        protected void onResume() {
    
            super.onResume();
    
            //let say that we want here to set a text on the textview  and it's available only for protrait 
            if(getScreenOrientation() == Configuration.ORIENTATION_PORTRAIT){
                //won't be null :) so we can set the text
                textView1.setText("Hello Guys!");
            }
    
        }
    
        // http://stackoverflow.com/a/6236110/671676
        public int getScreenOrientation() {
            Display getOrient = getWindowManager().getDefaultDisplay();
            int orientation = Configuration.ORIENTATION_UNDEFINED;
            if (getOrient.getWidth() == getOrient.getHeight()) {
                orientation = Configuration.ORIENTATION_SQUARE;
            } else {
                if (getOrient.getWidth() < getOrient.getHeight()) {
                    orientation = Configuration.ORIENTATION_PORTRAIT;
                } else {
                    orientation = Configuration.ORIENTATION_LANDSCAPE;
                }
            }
            return orientation;
        }
    }
    

    ask anything that you don’t understand .

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a universal iOS app with a custom view that has three buttons,
I have an AppDelegate which has 3 views. I add all three [window addSubview:gameViewController.view];
I have a view in my app that has three segmentedButtonControllers and I designed
I have an navigation-based app with three view controllers. The first has categories of
I have an Activity in Landscape-Mode. Inside there is a Custom-Title-View aligned like this:
My app has three text fields: 1) Username // Initialization code usernameTextField = [[UITextField
I am creating an app that has three tabs on the main screen. Each
I'm working on a rewrite of an app that has three categories of users
In ipad app I want to set UISplitViewController method set in portrait mode.(i.e Like
I'm building a custom view inside of Interface Builder that has buttons with image

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.