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 8346525
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:02:51+00:00 2026-06-09T07:02:51+00:00

I need my view to be placed in the center and it’s width is

  • 0

I need my view to be placed in the center and it’s width is not a match parent or wrap content but a size of particular percentage of a screen the app is running on. To have a more flexible layout I didn’t set its size using dimensions, but defined weights for the elements to have a required size of the main one. In order to do so I’ve inserted two additional LinearLayouts and defined weights for them. I don’t think this is the best solution to increase Views amount within the XML. Can you guys let me know the more efficient way of doing that?

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"
                  android:background="@drawable/right_back"
                  android:orientation="horizontal"
                  android:gravity="center">

<!-- The first one I think which is redundant -->
        <LinearLayout
            android:layout_weight="25"
            android:layout_width="0dip"
            android:layout_height="wrap_content"/>

<!-- Main view I need to be of a required size on each screen size -->
        <LinearLayout
            android:layout_width="0dip"
            android:layout_height="wrap_content"
            android:background="@drawable/layout_round_corners"
            android:orientation="vertical"
            android:layout_weight="50"
            android:padding="20dip">

            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:text="@string/welcome_text"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/text_color"
                android:layout_gravity="center_horizontal"/>

            <EditText
                android:id="@+id/edt_firsttimeactivity_first_field"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:hint="@string/password"
                android:password="true"
                android:singleLine="true"/>

            <EditText
                android:id="@+id/edt_firsttimeactivity_second_field"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/repeat_new_password_again"
                android:password="true"
                android:singleLine="true"/>

            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:onClick="onButtonClick"
                android:text="@string/create_account_for_me"/>
        </LinearLayout>

<!-- The second one I think which is redundant -->
        <LinearLayout
            android:layout_weight="25"
            android:layout_width="0dip"
            android:layout_height="wrap_content"></LinearLayout>


    </LinearLayout>
  • 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-09T07:02:52+00:00Added an answer on June 9, 2026 at 7:02 am

    This is how you should write the layout:

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
                  android:layout_width="match_parent"
                  android:layout_height="match_parent"                  
                  android:orientation="horizontal"
                  android:background="@drawable/right_back"
                  android:weightSum="1"
                  android:gravity="center">
    
    <!-- Main view I need to be of a required size on each screen size -->
        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:background="@drawable/layout_round_corners"
            android:layout_weight=".5"
            android:padding="20dp">
    
            <TextView
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/welcome_text"
                android:textAppearance="?android:attr/textAppearanceMedium"
                android:textColor="@color/text_color"
                android:layout_gravity="center_horizontal"/>
    
            <EditText
                android:id="@+id/edt_firsttimeactivity_first_field"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"                
                android:hint="@string/password"
                android:password="true"
                android:singleLine="true"/>
    
            <EditText
                android:id="@+id/edt_firsttimeactivity_second_field"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="@string/repeat_new_password_again"
                android:password="true"
                android:singleLine="true"/>
    
            <Button
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center_horizontal"
                android:onClick="onButtonClick"
                android:text="@string/create_account_for_me"/>
        </LinearLayout>
    </LinearLayout>
    

    Try this. You can change the layout_weight of the 2nd LinearLayout to make it look big or small as you like.

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

Sidebar

Related Questions

Need to display Update Progress at the center of a Grid view placed in
I need to view a site with an iPhone but it redirects me to
I have three view on the same place. I need to show them like
I need to view some of PVRTC-compressed textures from iPhone application (*.pvr) on OS
I have this in my controller. I need my view to generate some HTML,
In my view I need to visualize some audio data as waveform. I also
Im using a scroll view and need to make the view bigger so I
I am making game and need to prepare view for level selection. Could you
i am developing one application with map view i need display the weather depends
I am developing an iPad application in which I need a table view (

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.