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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:52:00+00:00 2026-06-04T14:52:00+00:00

I need to create text field which takes 70% of layout’s width (in linear

  • 0

I need to create text field which takes 70% of layout’s width (in linear layout). I use this code:

<EditText
    android:id="@+id/phone"
    android:layout_width="fill_parent"
    android:layout_weight=".7"
    android:layout_height="wrap_content"
    android:inputType="phone" >

The problem is that in such case height also takes 70% of layout’s height – but I don’t need to change it, just want it to be “wrap_content”. Is there any good solution?

UPD:
Would it be a good solution if I create a new horizontal-orientated linear layout and place my text field inside it? Or maybe something more elegant?

UPD(2):
I want it to look like below, but without using marginLeft and marginRgiht, which would give different percentage on a different screen resolution

enter image description here

  • 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-04T14:52:01+00:00Added an answer on June 4, 2026 at 2:52 pm

    You need to set weightSum on the parent of the control if you intend to use the weight. So yeah, put it in a LinearLayout and give the layout the proper parameters. Also, please remember that weight only affects the EXTRA space, so you want to set the width to 0dp, so the entire available space is considered “extra” space. Lastly, I think using integers for weight might be faster, but I’m not sure about that.

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:weightSum="4">
    
        <EditText
            android:id="@+id/phone"
            android:layout_width="0dp"
            android:layout_weight="3"
            android:layout_height="wrap_content"
            android:inputType="phone" />
    
    </LinearLayout>
    

    UPDATE:
    If you want it centered as well, then include some spacer views to the left and to the right, with the proper weights:

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:weightSum="1" >
    
        <View
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".15" />
    
        <EditText
            android:id="@+id/phone"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".7"
            android:inputType="phone" />
    
        <View
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight=".15" />
    
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need to create Perl code which allows counting paragraphs in text files. I
I would like to create this layout in Silverlight. The text need to wrap
i need to create a chart similar to this: link text Do you have
I need to create a fixed size ( height and width ) text area
I'm trying to use this gem to create a honeypot field, but I'm not
I need to create a calculator which call different function depending on which field
I need to create a full-text search form for a database of emails /
I need to create an ANSI text file from an Access recordset that outputs
I need to create some xaml that shows text in columns like newspaper, something
I need some JS class or CSS method to create from any text such

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.