2011-09-07 11 views
6

Podjęto próbę utworzenia układu czatu dla Androida w języku xml, ale nie mogłem uzyskać rzeczy, w których chciałem. To jest najbliższe, jakie mogę uzyskać:Tworzenie układu czatu?

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="10" > 
     <TextView 
      android:text="@string/text" 
      android:id="@+id/textOutput" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:paddingLeft="5dp" 
      android:paddingRight="5dp" 
      android:paddingTop="5dp" /> 
    </ScrollView> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_weight="100" 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp" 
     android:paddingBottom="5dp" 
     android:baselineAligned="true"> 
     <EditText android:layout_weight="1" android:id="@+id/textInput" 
      android:layout_height="45dp" android:layout_width="fill_parent"> 
      <requestFocus></requestFocus> 
     </EditText> 
     <Button android:layout_weight="1" android:text="Send" 
      android:layout_height="45dp" android:layout_width="125dp" 
      android:id="@+id/btnSend"></Button> 
    </LinearLayout> 
</LinearLayout> 

To skutkuje this. Problem z tym układem (który jest dość niechlujny) polega na tym, że nie chcę, aby wielkość dolnego LinearLayout była procentowa. Chcę, aby była to stała wysokość, a TextView w ScrollView (czy jest to najlepszy sposób na przewinięcie dużego tekstu?), Aby wypełnić resztę ekranu. Muszę brakować jakiegoś atrybutu lub czegoś.

Odpowiedz

8

Spróbuj nie dając dolna sekcja ciężar, ale po prostu owinąć treści, a następnie mają górny przewijania wypełnić pozostałą przestrzeń nadając jej ciężar 1. Podoba Ci się to

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"> 

    <ScrollView 
     android:layout_width="fill_parent" 
     android:layout_height="0dip" 
     android:layout_weight="1" > 
     <TextView 
      android:text="@string/text" 
      android:id="@+id/textOutput" 
      android:layout_width="fill_parent" 
      android:layout_height="wrap_content" 
      android:paddingLeft="5dp" 
      android:paddingRight="5dp" 
      android:paddingTop="5dp" /> 
    </ScrollView> 

    <LinearLayout 
     android:id="@+id/linearLayout1" 
     android:orientation="horizontal" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:paddingLeft="5dp" 
     android:paddingRight="5dp" 
     android:paddingBottom="5dp" 
     android:baselineAligned="true"> 
     <EditText android:layout_weight="1" android:id="@+id/textInput" 
      android:layout_height="45dp" android:layout_width="0dip"> 
      <requestFocus></requestFocus> 
     </EditText> 
     <Button android:text="Send" 
      android:layout_height="45dp" android:layout_width="125dp" 
      android:id="@+id/btnSend"></Button> 
    </LinearLayout> 
</LinearLayout> 
+0

Dziękuję bardzo! Czy mogę zapytać, co oznacza 0dip? Czy to jest to samo co 0dp? –

+0

Uważam, że oznacza to samo dla Androida. Jedyną ważną rzeczą związaną z używaniem tej wartości jest to, że jest ona skutecznym hackerem dla logiki układu. Służy ona do informowania Androida, że ​​ma tę wartość, aby wykonać ważenie (szerokość lub wysokość). Nie jest to wielka sprawa, wystarczy użyć dowolnej skali, która przekłada się na 0! – Kurru

Powiązane problemy