2016-07-28 6 views
1

こんにちは私はAndroid開発で新しく、ListViewScrollviewの内部にあってはならないという事実について話し、線形または相対レイアウトで折り返す必要があることを話しました。ListView collapse in CustomScrollView

しかし、私は、このレイアウト

<com.itmind.spac.spacapp.custom_extends.CustomScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:id="@+id/scrollViewreceipt" 
> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:orientation="vertical" android:layout_width="match_parent" 
android:layout_height="match_parent"> 

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

    <Spinner 
     android:id="@+id/customers_spinner" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:theme="@android:style/Theme.Holo.Light.DarkActionBar" 
     /> 
    <Spinner 
     android:id="@+id/venues_spinner" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:theme="@android:style/Theme.Holo.Light.DarkActionBar" 
     /> 
    <Spinner 
     android:id="@+id/workgroup_spinner" 
     android:layout_width="fill_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="20dp" 
     android:theme="@android:style/Theme.Holo.Light.DarkActionBar" 
     /> 

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:orientation="vertical" android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
      android:minHeight="150dp"> 
    <ListView 
     android:id="@+id/activityList" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="15dp" 
     android:minHeight="150dp" 
     /> 
    </LinearLayout > 

    <android.gesture.GestureOverlayView 
     android:id="@+id/signaturePad" 
     android:layout_width="match_parent" 
     android:layout_height="80dp" 
     android:layout_weight="5" 
     android:background="#d3d3d3" 
     android:eventsInterceptionEnabled="true" 
     android:fadeEnabled="false" 
     android:gestureColor="#333" 
     android:gestureStrokeLengthThreshold="0.1" 
     android:gestureStrokeType="multiple" 
     android:fadeOffset="5000" 
     android:orientation="vertical" > 
    </android.gesture.GestureOverlayView> 
    <Button 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:onClick="testImage" 
     android:text="testami"/> 
</LinearLayout> 

を持っており、これは私が

に触れたときにスクロールを有効に設定することができbeacause私はcustomclassスクロールビューを必要とする

public class CustomScrollView extends ScrollView { 

private boolean enableScrolling = true; 

public boolean isEnableScrolling() { 
    return enableScrolling; 
} 

public void setEnableScrolling(boolean enableScrolling) { 
    this.enableScrolling = enableScrolling; 
} 

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

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

public CustomScrollView(Context context) { 
    super(context); 
} 

@Override 
public boolean onInterceptTouchEvent(MotionEvent ev) { 

    if (isEnableScrolling()) { 
     return super.onInterceptTouchEvent(ev); 
    } else { 
     return false; 
    } 
} 
@Override 
public boolean onTouchEvent(MotionEvent ev) { 
    if (isEnableScrolling()) { 
     return super.onTouchEvent(ev); 
    } else { 
     return false; 
    } 
} 
} 

私custoScrollViewです

私の活動では、GestureOverlayView.OnGestureListenerを実装しています私は持っています:

@Override 
public void onGestureStarted(GestureOverlayView overlay, MotionEvent event) { 
    myScrollView.setEnableScrolling(false); 
} 
@Override 
public void onGestureEnded(GestureOverlayView overlay, MotionEvent event) { 
    myScrollView.setEnableScrolling(true); 
} 

多くの要素と私はすべての要素を表示するためにscrollViewする必要があります。 私のscrollViewの中には、私はデータベースから取得するデータを取り込むlistViewがあります。

私の問題は、私のリストビューが崩壊し、1行を表示し、1行で表示してスクロールすることです。

私はmin-heightを試しましたが、うまくいかず、Listviewにレイアウトの高さを置くと、このリストはスクロールできません。

どうすればいいですか? 私はリストを表示します。長いページで表示するので、scrollviewを使用する必要がありますか、またはソリューションはありますか?

+0

なぜカスタムスクロールビュークラスを使用していますか?コードを貼り付けます。 –

+0

こんにちは、私はのためにcustomScrollviewを使用します。 私のクラスを編集して貼り付けます。 – LorenzoBerti

答えて

0

をコードを追加ScrollView内側にその内容に基づいてListviewの高さを行います。 CustomScrollViewと同じ方法でxml-layoutファイルにListViewの代わりに使用してください。

public class CustomListView extends ListView { 

// private boolean expanded; 

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

    public CustomListView(Context context) { 
     super(context); 
    } 

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

    @Override 
    public void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     int expandSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, 
       MeasureSpec.AT_MOST); 
     super.onMeasure(widthMeasureSpec, expandSpec); 
    } 
} 

希望すると、これが役立ちます。

注: - ListViewのは、独自の垂直方向のスクロールの世話をするためのAndroid開発者向けウェブサイトのthisリンクを1として、私たちは、リストビューでScrollViewを使用しないでください。

+0

ありがとうございます。はい、それは動的な高さを固定しています。 私はScrollViewでListviewについて読んだことがありますが、私のデータベースから100の結果が得られた場合、listViewとScrollViewを使わずにどのように管理できますか? – LorenzoBerti

+1

CoordinatorLayoutは、ネストされたスクロールに使用できます。 https://developer.android.com/reference/android/support/design/widget/CoordinatorLayout.html –

+0

はい! :) Ok私はCoordinatorLayoutを勉強します – LorenzoBerti

1

あなた

よう
<ListView 
    android:id="@+id/activityList" 
    android:layout_width="match_parent" 
    android:layout_height="250dp" 
    android:layout_marginTop="15dp" 
    /> 

の修正高さとあなたの活動ファイルで指定したカスタムListViewクラス以下

listView.setOnTouchListener(new View.OnTouchListener() { 
     // Setting on Touch Listener for handling the touch inside ScrollView 
     @Override 
     public boolean onTouch(View v, MotionEvent event) { 
      // Disallow the touch request for parent scroll on touch of child view 
      v.getParent().requestDisallowInterceptTouchEvent(true); 
      return false; 
     } 
    }); 
+0

こんにちは、ありがとう、しかし、私は私のlistViewの高さを修正した場合、リストビューのスクロールが機能しないと私は私のlistViewがスクロール可能だったのが好きです – LorenzoBerti

+0

ありがとう、はい、リストビューはスクロールしないでも、私はScrollViewを置くとListViewに固定高さを設定します。 – LorenzoBerti