2013-03-04 2 views
2

У меня есть следующий xml для создания пользовательской строки для моего списка. Он работает нормально, но статус рядом с адресом - это слово, которое я не хочу. В прошлом я только что установил вес, и все было хорошо, но, похоже, это не играет в мяч.Android игнорирует параметр веса на пользовательской строке

Вот как это выглядит:

enter image description here

Вот что происходит по телефону:

enter image description here

Heres мой XML:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/LinearLayout1" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:background="@drawable/listviewonclick" 
    android:orientation="vertical" 
    android:padding="@dimen/Padding" > 

    <LinearLayout 
     android:id="@+id/linHoz" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="10" > 

     <TextView 
      android:id="@+id/status" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="3" 
      android:paddingLeft="@dimen/left" 
      android:text="Large Text" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="@color/cachecolor" 
      android:textSize="@dimen/MedText" /> 

     <TextView 
      android:id="@+id/txtSpacer" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="@dimen/left" 
      android:text=" | " 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="@color/yellow" 
      android:textSize="@dimen/MedText" /> 

     <TextView 
      android:id="@+id/Address" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="3" 
      android:paddingLeft="@dimen/left" 
      android:text="Large Text" 
      android:textAppearance="?android:attr/textAppearanceLarge" 
      android:textColor="@color/white" 
      android:textSize="@dimen/MedText" /> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linHoz2" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" > 

     <ImageView 
      android:id="@+id/icon" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_gravity="center_vertical" 
      android:clickable="true" 
      android:padding="10dp" 
      android:src="@drawable/ico_information" /> 

     <TextView 
      android:id="@+id/text" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:clickable="true" 
      android:padding="10dp" 
      android:layout_weight="6" 
      android:text="Medium Text" 
      android:textAppearance="?android:attr/textAppearanceMedium" /> 

     <Button 
      android:id="@+id/btnStart" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:background="@drawable/greenbuttons" 
      android:text="Start" /> 

    </LinearLayout> 

    <LinearLayout 
     android:id="@+id/linarea" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.50" > 

     <Button 
      android:id="@+id/btnMap" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="28dp" 
      android:layout_margin="4dp" 
      android:layout_weight="3" 
      android:background="@drawable/smallbluebutton" 
      android:text="Map" /> 

     <Button 
      android:id="@+id/btnInformation" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="28dp" 
      android:layout_margin="4dp" 
      android:layout_weight="3" 
      android:background="@drawable/smallpurplebuttons" 
      android:text="Information" /> 

     <Button 
      android:id="@+id/btnProblems" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="110dp" 
      android:layout_height="28dp" 
      android:layout_margin="4dp" 
      android:layout_weight="3" 
      android:background="@drawable/smallredbutton" 
      android:text="Problems" /> 
    </LinearLayout> 

</LinearLayout> 
+0

add android: sinleLine = "true" для текстового просмотра, если вы не хотите переносить слова. – Leonidos

ответ

0

Если не хватает места и для TextView «s показать все, что текст в одной строке быть, его либо перекоса или многоточие. По умолчанию TextView являются многострочными и будут обертывать текст. Чтобы вместо этого использовать многоточие, добавьте android:singleLine="true".

О распределении ширины текста: android:layout_width="0dp" для всех видов, участвующих в взвешенной планировке. Назначьте весы каждому, используя android:layout_weight в пропорции. Например. 0.3 для скачивания TextView и 0.7 для адреса TextView. Это даст 30% пространства для первого просмотра и 70% пространства для второго просмотра.

+0

Спасибо, я получил это, работая с этим – TMB87

0

Присвоить layout_weight ATT ребро только для адресной метки. Вы можете установить layout_width="0dip" для лучшей производительности. А также задайте ориентацию макета явно.

<LinearLayout 
    android:id="@+id/linHoz" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" > 

    <TextView 
     android:id="@+id/status" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Your Status" /> 

    <TextView 
     android:id="@+id/txtSpacer" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text=" | "/> 

    <TextView 
     android:id="@+id/Address" 
     android:layout_width="0dip" 
     android:layout_height="wrap_content" 
     android:layout_weight="1" 
     android:text="Very very long text goes here. Very very long text goes here." /> 

</LinearLayout> 
Смежные вопросы