2014-08-04 2 views
0

Мне нужно реализовать textview с равными размерами для 3 символов, но у меня есть проблема, если я добавлю: Эти четыре кнопки имеют разные размеры ... но я не знаю, почему и как я могу изменитьКак установить в текстовом виде одинаковые размеры

MOD 
_X_ 
_(_ 
_5_ 

_ белого пространство ..

Там в XML-код:

<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> 

Конец есть картина моей проблемы:

http://prntscr.com/49d6bo

+0

Добавьте код XML, который вы должны попробовать – MilapTank

+0

и можно установить размер кнопки фиксированного вместо wrap_content – KOTIOS

+0

пытаются использовать [GridView ] (http://developer.android.com/guide/topics/ui/layout/gridview.html) – kId

ответ

0

Дайте TextView ширину размер исправить, изменив layout_width от wrap_content до некоторого размера исправить йр как 30dp

Пример:

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

Попробуйте этот путь, надеюсь, что это поможет вам решить вашу проблему.

<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> 
0

похоже, что вы пытаетесь сделать кнопку в таблице, как в XML ???

не знаю, если это может помочь вам, но когда я пытаюсь сделать то же точную ширину я использовать это ...

здесь `s объяснение

создать 1 линейную компоновку с вертикальной ориентацией (поэтому, каждый раз, когда вы добавляете новый элемент, он будет помещаться вниз)

внутри него, вставить линейную компоновку с горизонтальной ориентацией ... (вставить столько строк, которые вы хотите, в вашем случае похоже, что вам нужно 5 линейных макетов с горизонтальной ориентация)

af ter, вставьте кнопку/текст в линейную компоновку (горизонтальная ориентация), поэтому ваша кнопка/текст будет размещаться горизонтально.

Если вы хотите изменить строку, просто вставьте кнопку/текст в другую линейную компоновку (горизонтальная ориентация).

после вставки все, установить линейную схему (горизонтальное значение) с этим кодом

android:weightSum="5" 

почему 5? потому что в вашем случае, сделайте 5 столбцов. и не забудьте установить width = fill parent.

после этого установить кнопку/TextView внутри LinearLayout (по горизонтали) с дополнительным этим кодом

android:layout_weight="1" 

и не забудьте изменить ширину с заполнением родителем.

с этим, я могу сделать точную ширину в каждом ряду.на следующем шаге вы можете установить маржу, чтобы ваша кнопка/текст выглядели хорошо.

надеюсь, что это может помочь вам ...

================================== === здесь `s код, если вы путаете с моим объяснением

<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> 

Смежные вопросы