user3859907
user3859907

Reputation: 35

how to set in textview same sizes

I need to implement textview with equal sizes for 3 character, but i have got some problem if i add: This four buttons have got diferent sizes ...but i dont know why, and how can i change

MOD
_X_
_(_
_5_

_ is white spaces..

There is xml code:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="1dp" >

<TextView
    android:id="@+id/item_text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"  
    android:textSize="12sp" >
</TextView>
<TextView
    android:id="@+id/item_text_Main"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"

    android:textSize="15sp" >
</TextView>

End there is picture of my problem:

http://prntscr.com/49d6bo

Upvotes: 0

Views: 109

Answers (3)

DumDum
DumDum

Reputation: 67

look like you try to make button in table like in XML???

don`t know if this can help you, but when i try to make same precise width i use this...

here`s the explanation

create 1 linear layout with vertical orientation (so, everytime you add new item, it will placed to down)

inside it, insert linear layout with horizontal orientation... (insert as many row you want, in you case looks like you need 5 linear layout with horizontal orientation)

after that, insert you button / textview inside the linear layout (horizontal orientation), so your button / text will placed horizontaly.

if you want to change row, just insert the button / textview inside another linear layout (horizontal orientation).

after you insert all, set the linear layout (horizontal value) with this code

android:weightSum="5"

why 5? because in your case, u make 5 column. and dont forget to set the width = fill parent.

after that set the button /textview inside the linearlayout (horizontal) with add this code

android:layout_weight="1"

and dont forget to change the width with fill parent.

with this, i can make precise width in every row. next step you can set the margin to make your button / textview looks good.

hope this can help you...

===================================== here`s the code if you confuse with my explanation

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context="com.example.tes.MainActivity"
tools:ignore="MergeRootFrame" >

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="5" >

    <Button
        android:id="@+id/Button22"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button21"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button24"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button23"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button20"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="5" >

    <Button
        android:id="@+id/Button17"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button16"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button19"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button18"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button15"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="5" >

    <Button
        android:id="@+id/Button12"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button11"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button14"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button13"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button10"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="5" >

    <Button
        android:id="@+id/Button07"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button06"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button09"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button08"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button05"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />
</LinearLayout>

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:weightSum="5">

    <Button
        android:id="@+id/Button04"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button03"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button02"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/Button01"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="Button" />

    <Button
        android:id="@+id/button1"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:text="Button" 
        android:layout_weight="1"/>

</LinearLayout>

Upvotes: 0

Hareshkumar Chhelana
Hareshkumar Chhelana

Reputation: 24848

Try this way,hope this will help you to solve your problem.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <EditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:lines="4"/>

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="10dp"
            android:gravity="center"
            android:text="MC_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="MS_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="M+_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="_(_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="_)_"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginTop="5dp">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="10dp"
            android:gravity="center"
            android:text="MC_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="MS_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="M+_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="_(_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="_)_"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginTop="5dp">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="10dp"
            android:gravity="center"
            android:text="MC_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="MS_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="M+_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="_(_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="_)_"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginTop="5dp">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="10dp"
            android:gravity="center"
            android:text="MC_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="MS_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="M+_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="_(_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="_)_"/>
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginTop="5dp">
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="10dp"
            android:gravity="center"
            android:text="MC_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="MS_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="M+_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="_(_"/>
        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:padding="5dp"
            android:gravity="center"
            android:layout_marginLeft="5dp"
            android:text="_)_"/>
    </LinearLayout>
</LinearLayout>

Upvotes: 1

Maverick
Maverick

Reputation: 3053

Give your TextView a fix size width by changing layout_width from wrap_content to some fix dp size like 30dp

Example:

  <TextView
        android:id="@+id/item_text"
        android:layout_width="32dp"
        android:layout_height="wrap_content"
        android:text="MOD"
        android:textSize="12sp" >
    </TextView>

Upvotes: 0

Related Questions