2017-09-10 4 views
0

Meine ListView besteht aus drei TextViews, sagen T1, T2 und T3. Ich habe auch zwei Tasten, B1 und B2ListView mit TextView und Tasten

ich sie wie folgt angezeigt werden soll:

B1 [Space Between Tasten] B2
T1
T2
T3

Die T1 usw. sind auf dem Bildschirm unter den Tasten und nicht nur unter B1.

Unten ist meine XML, die ich nach vielen Antworten auf SO Fragen zu ändern versuchte.

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

     <Button 
      android:id="@+id/button" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:text="Left Button" 
      /> 
     <Button 
      android:id="@+id/button2" 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:text="Right Button" 
      /> 
    </LinearLayout> 
    <TextView 
     android:id="@+id/engText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="10sp" 
     android:textSize="15sp" 
     android:typeface="serif"/> 

    <TextView 
     android:id="@+id/arabText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="10sp" 
     android:textSize="15sp" 
     android:typeface="sans" 
     /> 
    <TextView 
     android:id="@+id/refText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="10sp" 
     android:textSize="15sp" /> 

    <ListView 
     android:id="@+id/hadithView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
    </ListView> 
</RelativeLayout> 

Kann jemand bitte helfen. Danke

EDIT ich CursorAdapter bin mit den Ansichten zu füllen. Die B1 und B2 werden mit TextViews wiederholt. Ich mag B1 und B2 an der Spitze halten (fest) und in der Lage, die Textansichten blättern (ohne eigene Tasten)

EDIT 2 ich das Buttons Problem behoben. Obwohl ich auch oben zwei Knöpfe brauche. Ich habe sie entfernt und habe jetzt zwei Buttons mit Textansichten, was ich später sowieso brauche.

Jetzt Der Text wird sich gegenseitig auferlegt.

Hier ist meine neue xml:

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="0sp" 
      android:layout_weight="0.5" 
      android:layout_height="wrap_content" 
      android:text="Left Button" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="0sp" 
      android:layout_weight="0.5" 
      android:layout_height="wrap_content" 
      android:text="Right Button" /> 
    </LinearLayout> 
    <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 
     <TextView 
      android:id="@+id/engText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginStart="10sp" 
      android:textSize="15sp" 
      android:typeface="serif"/> 

     <TextView 
      android:id="@+id/arabText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginStart="10sp" 
      android:textSize="15sp" 
      android:typeface="sans" 
      /> 
     <TextView 
      android:id="@+id/refText" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginStart="10sp" 
      android:textSize="15sp" /> 
    </RelativeLayout> 
</LinearLayout> 

Antwort

0

Sie RelativeLayout und halten verschiedene Abschnitte in verschiedenen RelativeLayout relativ zueinander und verwenden sein Attribut layout_below

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:orientation="vertical" > 
<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical" 
    //give some id 
    android:id="@+id/one"> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.5" 
     android:text="Left Button" 
     /> 
    <Button 
     android:id="@+id/button2" 
     android:layout_width="0dp" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.5" 
     android:text="Right Button" 
     /> 
</LinearLayout> 
<RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
android:layout_below="@+id/one"> 
<TextView 
    android:id="@+id/engText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginStart="10sp" 
    android:textSize="15sp" 
    android:typeface="serif"/> 

<TextView 
    android:id="@+id/arabText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginStart="10sp" 
    android:textSize="15sp" 
    android:typeface="sans" 
    /> 
<TextView 
    android:id="@+id/refText" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_marginStart="10sp" 
    android:textSize="15sp" /> 

<ListView 
    android:id="@+id/hadithView" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" > 
</ListView> 

0

Es können sieht so aus, als ob Sie LinearLayout und nicht RelativLayout verwenden sollten. Weil die Reihenfolge Ihrer Artikel nur linear vertikal geordnet ist. Hier ist der Code:

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

     <Button 
      android:id="@+id/button" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:text="Left Button" 
      /> 
     <Button 
      android:id="@+id/button2" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="0.5" 
      android:text="Right Button" 
      /> 
    </LinearLayout> 
    <TextView 
     android:id="@+id/engText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="10sp" 
     android:textSize="15sp" 
     android:text="T1" 
     android:typeface="serif"/> 

    <TextView 
     android:id="@+id/arabText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="10sp" 
     android:textSize="15sp" 
     android:text="T2" 
     android:typeface="sans" 
     /> 
    <TextView 
     android:id="@+id/refText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="10sp" 
     android:text="T3" 
     android:textSize="15sp" /> 

    <ListView 
     android:id="@+id/hadithView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" > 
    </ListView> 
</LinearLayout> 
+0

Vielen Dank für Ihre Antwort. Dies funktioniert teilweise. Schaltflächen werden mit Textansichten wiederholt und zwei bleiben oben (fixiert). Im Moment möchte ich nur die ersten zwei Knöpfe haben. Bitte beachten Sie meine EDIT zu OP –

+0

vielleicht sollten Sie darüber nachdenken, die Symbolleiste zu verwenden, um Sachen zu tun, die immer oben fixiert ist? Wenn nicht, dann kann Ihnen vielleicht ein explicit ScollView helfen. – deadpoint

+0

:) Ich komme aus 'WebView'. Meine App war fast fertig, aber 'WebView' zeigte einen Defekt (zu langsam um große HTML Daten zu laden). Also kam ich zu 'Listview' und hoffte, dass es schneller geht. Es ist meine erste App. Lassen Sie sehen, wie diese Ansicht geht. Vielen Dank für Ihre Vorschläge:) –

0
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/one" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:weightSum="1"> 

    <Button 
     android:id="@+id/button" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.5" 
     android:text="Left Button" /> 

    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_weight="0.5" 
     android:text="Right Button" /> 
</LinearLayout> 

Dadurch wird festgelegt, die beiden Tasten nebeneinander, und dann können Sie alle unter Elemente im Rahmen dieser Linearlayout platzieren.

Änderungen vorgenommen:

  • Linearlayout Orientierung horizontal
  • Linearlayout hält weigthSum von 1
  • layout_width beiden Tasten eingestellt geändert wrap_content (Sie werden nach wie vor ihren Platz, weil von 0,5 Gewicht halten - also teilten sie beide die Sichtweise.

Button layout

Wenn Sie mehr Platz wollen zwischen Tasten setzen auf der linken Taste wie diese som Marge.

android:layout_marginRight="32dp" 
android:layout_marginEnd="32dp" 
1

Dies ist eine sehr schnelle Lösung - aber es gibt, was Sie wollen. Grundsätzlich gilt: Ihre Listenansicht übernimmt den gesamten Bildschirm - und Sie scheinen es nicht entsprechend Ihrer Frage zu brauchen. Sie können oben einen ListView mit einem leeren TextView als Ihren "Space" verwenden, aber dann müssen Sie den TextViews unter Attribute geben, wo sie in RelativeLayout (Ihr Hauptlayout) platziert werden sollen. Ich habe schnell Attribute in Bezug auf das LinearLayout (für das erste TextView) und dann in Bezug auf das obige TextView für alle unten hinzugefügt. Du kannst es anders machen - und generell denke ich, dass du die Dokumentation für XML-Dateien in Android nachschlagen solltest und/oder einfach ein bisschen herumspielen sollst. Es ist alles ziemlich logisch, aber ich hatte auch Probleme, als ich anfing. Hier ist mein Code:

<?xml version="1.0" encoding="utf-8"?> 
 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
 
    android:layout_width="match_parent" 
 
    android:layout_height="match_parent" 
 
    android:orientation="vertical" > 
 
    <LinearLayout 
 
     android:id="@+id/linLay" 
 
     android:layout_width="match_parent" 
 
     android:layout_height="wrap_content" 
 
     android:orientation="horizontal"> 
 

 
     <Button 
 
      android:id="@+id/button" 
 
      android:layout_width="100dp" 
 
      android:layout_height="wrap_content" 
 
      android:layout_weight="0.4" 
 
      android:text="Left Button" 
 
      /> 
 
     <TextView 
 
      android:layout_width="10dp" 
 
      android:layout_height="wrap_content" 
 
      android:layout_weight="0.1"/> 
 
     <Button 
 
      android:id="@+id/button2" 
 
      android:layout_width="100dp" 
 
      android:layout_height="wrap_content" 
 
      android:layout_weight="0.4" 
 
      android:text="Right Button" 
 
      /> 
 
    </LinearLayout> 
 
    <TextView 
 
     android:id="@+id/engText" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_marginStart="10sp" 
 
     android:layout_below="@+id/linLay" 
 
     android:layout_marginTop="10dp" 
 
     android:textSize="15sp" 
 
     android:text="My dummy text" 
 
     android:typeface="serif"/> 
 

 
    <TextView 
 
     android:id="@+id/arabText" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_marginStart="10sp" 
 
     android:layout_below="@+id/engText" 
 
     android:layout_marginTop="10dp" 
 
     android:textSize="15sp" 
 
     android:text="My dummy text" 
 
     android:typeface="sans" 
 
     /> 
 
    <TextView 
 
     android:id="@+id/refText" 
 
     android:layout_width="wrap_content" 
 
     android:layout_height="wrap_content" 
 
     android:layout_marginStart="10sp" 
 
     android:layout_below="@+id/arabText" 
 
     android:layout_marginTop="10dp" 
 
     android:textSize="15sp" 
 
     android:text="My dummy text"/> 
 
</RelativeLayout>

+0

Vielen Dank für Ihre Antwort. Können Sie bitte einen Blick auf meine Bearbeitung zu OP. –

0

das Problem behoben. Das ist mein xml, die ich mit dem

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

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal"> 

     <Button 
      android:id="@+id/button" 
      android:layout_width="0sp" 
      android:layout_weight="0.5" 
      android:layout_height="wrap_content" 
      android:text="Left Button" /> 

     <Button 
      android:id="@+id/button2" 
      android:layout_width="0sp" 
      android:layout_weight="0.5" 
      android:layout_height="wrap_content" 
      android:text="Right Button" /> 
    </LinearLayout> 
    <TextView 
     android:id="@+id/engText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="10sp" 
     android:textSize="15sp" 
     android:typeface="serif"/> 

    <TextView 
     android:id="@+id/arabText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="10sp" 
     android:textSize="15sp" 
     android:typeface="sans" 
     /> 
    <TextView 
     android:id="@+id/refText" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginStart="10sp" 
     android:textSize="15sp" /> 
</LinearLayout> 

CursorAdapter verwendet Und das ist mein Activity xml:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" > 
    <ListView 
     android:id="@+id/hadView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content"> 
    </ListView> 
</LinearLayout> 

Sie alle danken, die geantwortet haben.

Verwandte Themen