2017-07-20 6 views
0

Hallo, ich habe Probleme beim Scrollen, bis das letzte Scrolling in der Mitte aufhört, hier ist mein Layoutcode.Listview scrollt nicht bis zum letzten Eintrag

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="fragment.Equivalent"> 
<ListView 
    android:id="@+id/listView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:visibility="visible" 
    android:layout_alignParentTop="true" 
    android:layout_alignParentStart="true" 
    android:focusable="false"/> 

<TextView 
    android:id="@+id/txt404" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true" 
    android:text="Message that will be shown if the listview is empty" 
    android:textSize="21dp" 
    android:textStyle="bold" 
    android:visibility="invisible" /> 
</RelativeLayout> 
+0

Überprüfen Sie, ob die Größe der 'ListView' isn ist 't länger als das 'RelativeLayout'. Wenn dies der Fall ist, besteht das Problem möglicherweise nicht beim Scrollen, sondern darin, wie viel von der tatsächlichen Liste Sie auf dem Bildschirm sehen können. Versuchen Sie 'android: layout_height =" match_parent "' für die 'ListView' – moondaisy

+0

@Fatal Könnten Sie den Code des Fragments teilen? – VIX

Antwort

0

Lösung wurde das Layout zu einem Constraint-Layout ändern und die Größe der Listenansicht zu ändern

<android.support.constraint.ConstraintLayout 
xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:app="http://schemas.android.com/apk/res-auto" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
tools:context="fragment"> 

<ListView 
    android:id="@+id/listView" 
    android:layout_width="399dp" 
    android:layout_height="485dp" 
    android:layout_marginEnd="8dp" 
    android:layout_marginRight="0dp" 
    android:focusable="false" 
    android:visibility="visible" 
    app:layout_constraintHorizontal_bias="0.0" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    tools:layout_constraintLeft_creator="1" 
    tools:layout_constraintTop_creator="1" 
    app:layout_constraintBottom_toBottomOf="parent" 
    android:layout_marginBottom="8dp" 
    app:layout_constraintVertical_bias="0.0" /> 

<TextView 
    android:id="@+id/txt404" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="" 
    android:textSize="21dp" 
    android:textStyle="bold" 
    android:visibility="invisible" 
    tools:layout_constraintTop_creator="1" 
    tools:layout_constraintRight_creator="1" 
    tools:layout_constraintBottom_creator="1" 
    app:layout_constraintBottom_toBottomOf="parent" 
    app:layout_constraintRight_toRightOf="parent" 
    tools:layout_constraintLeft_creator="1" 
    app:layout_constraintLeft_toLeftOf="parent" 
    app:layout_constraintTop_toTopOf="parent" 
    app:layout_constraintHorizontal_bias="0.503" 
    app:layout_constraintVertical_bias="0.391" /> 

    </android.support.constraint.ConstraintLayout> 
0

Versuchen mit einer Scroll-Ansicht:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    tools:context="fragment.Equivalent"> 
    <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentEnd="true" 
      android:scrollbarStyle="insideOverlay" 
      style="@android:style/Widget.Holo.ScrollView"> 
    <TableLayout 
     android:id="@+id/table_layout_id" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
    </TableLayout> 
    </ScrollView> 
</RelativeLayout> 

in Java-Datei, dies zu tun:

TableLayout ll = (TableLayout) findViewById(R.id.table_layout_id); 
TableRow row = new TableRow(this);
  
TableRow.LayoutParams lp = new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT);
  
row.setLayoutParams(lp); 

 
 butt = new Button(this);
 //You can add button too, FYI 
butt.setText("TEST");
 
 
  
TextView tv = (TextView) findViewById(R.id.txt404); 

tv.setText("Text view");
  
tv2 = new TextView(this);
 //your job: add list view here 
tv2.setText("Text View 2");
 
 
  
row.addView(butt); 

 row.addView(tv1);
  
row.addView(tv2);
 
  
ll.addView(row, i); // where i is the row number, increment on addition 
+0

Ich bekomme eine Ausnahme java.lang.IllegalStateException: ScrollView kann nur ein direktes Kind hosten – Fatal

+0

aktualisiert meine Antwort – Enigma

Verwandte Themen