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

  • SEARCH
  • Home
  • 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 8795579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:25:07+00:00 2026-06-13T23:25:07+00:00

I have a form that I want to display in a single column of:

  • 0

I have a form that I want to display in a single column of:

     account name
______________________

       password
______________________

[       connect       ]

when horizontal space is limited (i.e. portrait orientation). And I want it to flow into a two column orientation when horizontal space is abundant:

account name _________________
    password _________________
[          connect            ]      

I know you can do this with a pair of layout resources, but I would like to only have one layout with a dynamic number of columns.

  • 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-13T23:25:08+00:00Added an answer on June 13, 2026 at 11:25 pm

    This may not be a useful example, but the approach might prove useful.

    First, the GridLayout

    <GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal"
            android:padding="16dp"
            android:useDefaultMargins="true"
            android:columnCount="@integer/create_account_pane_column_count"
            android:alignmentMode="alignBounds" >
    
    <!-- Error messages -->
    <TextView
            android:id="@+id/errors"
            android:layout_columnSpan="@integer/create_account_pane_column_count"
            android:textColor="@color/error_red"
            android:textSize="@dimen/small_text_size" />
    
    <TextView
            android:id="@+id/account_name_label"
            android:layout_gravity="fill_horizontal"
            android:text="@string/label_account_name"
            android:textColor="?android:textColorSecondary" />
    
    <EditText
            android:id="@+id/account_name"
            android:layout_gravity="fill_horizontal"
            android:ems="10"
            android:hint="@string/hint_account_name"
            android:inputType="textNoSuggestions" >
    
        <requestFocus />
    </EditText>
    
    <TextView
            android:id="@+id/password_label"
            android:layout_gravity="fill_horizontal"
            android:text="@string/label_password"
            android:textColor="?android:textColorSecondary" />
    
    <EditText
            android:id="@+id/password"
            android:layout_gravity="fill_horizontal"
            android:ems="10"
            android:hint="@string/hint_password"
            android:inputType="textPassword" />
    
    <Button
            android:id="@+id/connect"
            android:layout_columnSpan="@integer/create_account_pane_column_count"
            android:layout_gravity="fill_horizontal"
            android:text="@string/connect" />
    
    <Button style="?android:borderlessButtonStyle"
            android:id="@+id/create_account"
            android:layout_columnSpan="@integer/create_account_pane_column_count"
            android:layout_gravity="center_horizontal"
            android:text="@string/create_a_new_account"
            android:textColor="@color/kas_yellow" />
    
    </GridLayout>
    

    Then I have two integer resource files, values-large-land-v11/integers.xml has <integer name="create_account_pane_column_count">2</integer> and values/integers.xml has <integer name="create_account_pane_column_count">1</integer>. This gives dynamic columns, where there is one column unless the device and orientation matches large land v11 (7″ tablets and above in landscape orientation).

    Finally, to get the labels to align nicely (i.e centered when stacked and right aligned when inline) I set it programmatically since the xml value didn’t seem to accept a resource (neither integer nor string).

    @Override
    public void onConfigurationChanged(Configuration new_configuration) {
        super.onConfigurationChanged(new_configuration);
    
        alignLabels();
    }
    
    /**
     * Aligns the labels depending on the number of columns in the layout
     */
    private void alignLabels() {
        final int column_count = getResources().getInteger(R.integer.create_account_pane_column_count);
        final int gravity = column_count == 1? Gravity.CENTER_HORIZONTAL : Gravity.RIGHT;
        _account_name_label.setGravity(gravity);
        _password_label.setGravity(gravity);
    }
    

    Also call alignLabels() in the onCreate or onCreateView (for Fragments) to set the gravity on the initial page layout.

    Side note: my labels use my accent color when their associated field has focus if you notice that.

    landscape orientation
    portrait orientation

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

Sidebar

Related Questions

I have a form in a Windows form application that I want to display
I have a form that posts to a page. I want to display an
I have a form that I want to be validated before showing it initially.
I have a form that i want to appear at the top of every
I have a form that i want an administrator to fill out, then click
I have a form that i want to auto populate the last 2 fields
Okay all, I have a form that I want users to fill out. When
I have a small form that I want to have people fill out on
I want to have a Form that can Add or Delete TextFields. I was
I have a form that validates the email address and I want to be

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.