6

Ich versuche, ein Layout mit einer Kopfzeile, ein Banner darunter und dann ein paar ListView unter dem Banner zu erstellen. Ich möchte, dass der komplette Bildschirm scrollbar ist, außer der Kopfzeile. Jetzt weiß ich, dass ListView nicht innerhalb einer ScrollView scrollt, also habe ich die Höhe der ListView groß genug eingestellt, um alle Elemente anzuzeigen. Das Problem ist, dass ich selbst nach diesen Änderungen sehe, dass der ListView unabhängig scrollt und der gesamte Bildschirm nicht scrollbar ist.Android: ScrollView scrollt nicht

`

<include 
    android:id="@+id/logo_header" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    layout="@layout/screen_header" /> 

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:layout_weight="0.8" 
      android:background="#f2f2f2"> 

      <include 
       android:id="@+id/mcUser" 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       layout="@layout/complaint_reporters_details" 
       android:layout_weight="2" /> 

      <LinearLayout 
       android:layout_width="fill_parent" 
       android:layout_height="fill_parent" 
       android:orientation="horizontal" 
       android:weightSum="9" 
       android:layout_weight="2"> 

       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:orientation="vertical" 
        android:weightSum="1" 
        android:layout_weight="3" 
        android:focusableInTouchMode="false" 
        android:paddingLeft="30dp" 
        android:paddingRight="30dp"> 

        <ImageView android:id="@+id/mcShowList" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:gravity="center" 
         android:layout_marginTop="5dp" 
         android:layout_marginBottom="5dp" 
         android:scaleType="fitXY" 
         android:src="@drawable/list_icon" 
         android:layout_weight="0.2" /> 

        <TextView android:id="@+id/mcShowList_label" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:gravity="center" 
         android:textStyle="bold" 
         android:textSize="12sp" 
         android:textColor="#929292" 
         android:maxLines="1" 
         android:text="List" 
         android:layout_weight="0.8" 
         android:layout_marginTop="-8dp" /> 

       </LinearLayout> 

       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:orientation="vertical" 
        android:weightSum="1" 
        android:layout_weight="3" 
        android:gravity="center_vertical|center_horizontal" 
        android:paddingLeft="30dp" 
        android:paddingRight="30dp"> 

        <ImageView android:id="@+id/mcShowMap" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:gravity="center" 
         android:layout_marginTop="5dp" 
         android:layout_marginBottom="5dp" 
         android:scaleType="fitXY" 
         android:src="@drawable/map_view" 
         android:layout_weight="0.2"/> 

        <TextView android:id="@+id/mcShowMap_label" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:gravity="center" 
         android:textStyle="bold" 
         android:textSize="12sp" 
         android:textColor="#929292" 
         android:maxLines="1" 
         android:text="Map" 
         android:layout_weight="0.8" 
         android:layout_marginTop="-8dp" /> 
       </LinearLayout> 

       <LinearLayout 
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent" 
        android:orientation="vertical" 
        android:weightSum="1" 
        android:layout_weight="3" 
        android:focusableInTouchMode="false" 
        android:paddingRight="30dp" 
        android:paddingLeft="30dp"> 

        <ImageView android:id="@+id/mcShowAnalytics" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:gravity="center" 
         android:layout_marginTop="5dp" 
         android:layout_marginBottom="5dp" 
         android:scaleType="fitXY" 
         android:src="@drawable/analytics_icon" 
         android:layout_weight="0.2" /> 

        <TextView android:id="@+id/mcShowAnalytics_label" 
         android:layout_width="fill_parent" 
         android:layout_height="fill_parent" 
         android:gravity="center" 
         android:textStyle="bold" 
         android:textSize="12sp" 
         android:textColor="#929292" 
         android:maxLines="1" 
         android:text="Analytics" 
         android:layout_weight="0.8" 
         android:layout_marginTop="-10dp" /> 

       </LinearLayout> 

      </LinearLayout> 

     </LinearLayout> 

     <RelativeLayout 
      android:layout_weight="0.2" 
      android:layout_width="fill_parent" 
      android:layout_height="400dp"> 

      <FrameLayout 
       android:id="@+id/mcMapContainer" 
       android:layout_width="match_parent" 
       android:layout_height="fill_parent"/> 

      <LinearLayout 
       android:id="@+id/mcAnalyticsContainer" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="fill_parent"> 

       <FrameLayout 
        android:id="@+id/mcChartContainer" 
        android:layout_gravity="center" 
        android:layout_width="200dp" 
        android:layout_height="200dp"/> 

       <GridView 
        android:id="@+id/mcAmenityList" 
        android:layout_height="0dp" 
        android:layout_weight="7" 
        android:layout_width="match_parent" 
        android:numColumns="3"/> 

      </LinearLayout> 

      <LinearLayout 
       android:id="@+id/mcListContainer" 
       android:orientation="vertical" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:weightSum="1"> 

       <TextView 
        android:text="Open Complaints" 
        android:textColor="@color/red_btn_bg_color" 
        android:textSize="18dp" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center_vertical|center_horizontal" 
        android:padding="5dp" /> 

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

       <TextView 
        android:text="Closed Complaints" 
        android:textColor="@color/red_btn_bg_color" 
        android:textSize="18dp" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center_vertical|center_horizontal" 
        android:padding="5dp" /> 

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

      </LinearLayout> 

     </RelativeLayout> 

    </LinearLayout> 

</ScrollView> 

`

+0

Siehe meine Antwort im folgenden Beitrag [Hinzufügen eines weiteren Ansicht] (https://stackoverflow.com/questions/30282580/scrollview-not-scrolling -android) –

+0

Bitte sehen Sie meine Antwort in einer anderen Frage .. [Hinzufügen einer weiteren leeren Ansicht] (https://stackoverflow.com/questions/30282580/scrollview-not-scrolling-android) –

Antwort

7

ändern Höhe der Scroll-Ansicht von match_parent wrap_content. Da die Bildlaufansicht nur das Blättern ermöglicht, wenn die Gesamthöhe größer als die Höhe der übergeordneten Ansicht ist. dh ersetzen

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:fillViewport="true"> 

mit diesem Code:

<ScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:fillViewport="true"> 
+0

Ich habe sowohl die Layouthöhe als auch die Breite auf "wrap_content" gesetzt. Noch Scroll funktioniert nicht. – vaibhav

+1

Ändern Sie die Höhe der linearen Layouts auch zu wrap_content, dann versuchen Sie es. –

+0

Ich hatte das getan. Habe aber gerade gemerkt, dass die Höhe des RelativeLayout, das den ListView hat, behoben wurde. Durch Ändern in "fill_parent" wurde das Problem behoben. – vaibhav

0

Sie können dies versuchen,

listView.setOnTouchListener(new OnTouchListener() { 

public boolean onTouch(View v, MotionEvent event) { 
    if (event.getAction() == MotionEvent.ACTION_MOVE) { 
     return true; 
    } 
    return false; 
    } 
    }); 
2

ich die folgende Methode mehrmals bei verschiedenen Anwendungen verwendet haben. Ich verwende eine spezielle Unterklasse von Listview:

package com.yourcompany.appname.views; 

import android.content.Context; 
import android.util.AttributeSet; 
import android.view.ViewGroup; 
import android.widget.ListView; 

public class NonScrollableListView extends ListView { 
    public NonScrollableListView(Context context) { 
     super(context); 
    } 

    public NonScrollableListView(Context context, AttributeSet attrs) { 
     super(context, attrs); 
    } 

    public NonScrollableListView(Context context, AttributeSet attrs, int defStyle) { 
     super(context, attrs, defStyle); 
    } 

    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     int heightMeasureSpec_custom = MeasureSpec.makeMeasureSpec(
       Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); 
     super.onMeasure(widthMeasureSpec, heightMeasureSpec_custom); 
     ViewGroup.LayoutParams params = getLayoutParams(); 
     params.height = getMeasuredHeight(); 
    } 
} 

Dann in Ihrem Layout, anstelle der Verwendung von ‚s, verwenden Sie so etwas wie folgt aus:

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 
    <com.yourcompany.appname.views.NonScrollableListView 
     android:id="@+id/listId" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     /> 
</LinearLayout> 

hoffe, das hilft!

+0

Danke Jonathan. Dadurch wird das ListView vollständig erweitert, was ich auch vorher gemacht habe, obwohl dies eine bessere und klarere Art ist, dies zu tun. Aber selbst jetzt scrollt die ScrollView nicht für mich und ich kann nur Elemente sehen, die auf den Bildschirm passen. – vaibhav

+0

@vaibhav, Sie haben in Ihrer relativen Ansicht auch eine Höhe von 400 dpi eingestellt. Sollte das wrap_content sein, damit in der Bildlaufansicht etwas zu scrollen ist? Im Allgemeinen sollten die Ansichten in der Bildlaufansicht Inhalte vertikal umbrechen, sodass sie den zusätzlichen vertikalen Platz verwenden, der von der Bildlaufansicht bereitgestellt wird. – Jon

+0

Das ist richtig. Das habe ich gestern bemerkt und behoben. Danke für die Hilfe. Leider habe ich nicht genug Reputationspunkte, um deine Antwort zu verbessern. – vaibhav

0

Put-Listenansicht auf eine andere XML und schließen es so unter

<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"> 
<include layout="@layout/show_message_header" /> 
    <ScrollView 
     android:id="@+id/myscrollview_Show_message" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="@dimen/header" 
     android:fadingEdge="none" 
     android:fillViewport="false" 
     android:paddingRight="0dp" 
     android:scrollbarAlwaysDrawVerticalTrack="false" 
     android:scrollbarSize="0dp" 
     android:scrollbarStyle="insideOverlay" 
     android:scrollbars="none" > 
     <TableLayout 
      android:id="@+id/Show_message_dynamic_table" 
      android:layout_width="match_parent" 
      android:layout_height="fill_parent" > 
      <include layout="@layout/desinglayoutforlistviewincludehere" /> 
     </TableLayout> 
    </ScrollView> 

Verwandte Themen