2011-07-13 25 views
3

私のUIにはgridviewが1つありますが、垂直方向にスクロールします。すべてのスクロールバーのプロパティをfalseに設定していますが、それでもスクロールしています。なぜこれがそうなの?助けてください。 enter image description hereグリッドビューのスクロールを固定する

これは

<?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:background="@drawable/bg_im" android:id="@+id/rLayout" android:isScrollContainer="false"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/lLayoutCalendar" android:orientation="vertical" 
     android:layout_width="wrap_content" android:layout_height="wrap_content" 
     android:layout_toRightOf="@+id/linearLayoutLeftTask" android:gravity="center_horizontal" 
     android:layout_marginLeft="10dp" android:layout_marginRight="10dp" 
     android:layout_marginTop="20dp" android:background="@drawable/calendar_bgnew" android:isScrollContainer="false"> 

     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:layout_gravity="center_vertical" 
      android:scrollbars="none" android:isScrollContainer="false" 
      android:layout_marginTop="8dp"> 

      <ImageView android:id="@+id/prevMonth" 
       android:layout_width="wrap_content" android:layout_marginLeft="10dp" 
       android:layout_marginTop="5dp" android:layout_height="wrap_content" 
       android:src="@drawable/calendar_arrow_previous"> 
      </ImageView> 
      <Button android:id="@+id/currentMonth" android:layout_weight="0.8" 
       android:textColor="@android:color/black" android:textAppearance="?android:attr/textAppearanceMedium" 
       android:background="@android:color/transparent" android:textStyle="bold" 
       android:textSize="16sp" android:layout_width="wrap_content" 
       android:layout_height="wrap_content"> 
      </Button> 
      <ImageView android:id="@+id/nextMonth" 
       android:layout_marginRight="10dp" android:layout_marginTop="5dp" 
       android:layout_width="wrap_content" android:layout_height="wrap_content" 
       android:src="@drawable/calendar_arrow_next"> 
      </ImageView> 
     </LinearLayout> 
     <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
      android:orientation="horizontal" android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:paddingLeft="5dp" 
      android:layout_marginTop="10dp" android:paddingRight="5dp"> 

      <TextView android:typeface="sans" android:layout_marginTop="12dp" 
       android:paddingLeft="5dp" android:text="Su" android:layout_height="wrap_content" 
       android:textStyle="normal" android:textColor="#7e7f7e" 
       android:layout_width="65px"> 
      </TextView> 
      <TextView android:typeface="sans" android:layout_marginTop="12dp" 
       android:text="Mo" android:layout_height="wrap_content" 
       android:textStyle="normal" android:textColor="#7e7f7e" 
       android:layout_width="65px"> 
      </TextView> 
      <TextView android:typeface="sans" android:layout_marginTop="12dp" 
       android:text="Tu" android:layout_height="wrap_content" 
       android:textStyle="normal" android:textColor="#7e7f7e" 
       android:layout_width="63px"> 
      </TextView> 
      <TextView android:typeface="sans" android:layout_marginTop="12dp" 
       android:text="We" android:layout_height="wrap_content" 
       android:textStyle="normal" android:textColor="#7e7f7e" 
       android:layout_width="63px"> 
      </TextView> 
      <TextView android:typeface="sans" android:layout_marginTop="12dp" 
       android:text="Th" android:layout_height="wrap_content" 
       android:textStyle="normal" android:textColor="#7e7f7e" 
       android:layout_width="63px"> 
      </TextView> 
      <TextView android:typeface="sans" android:layout_marginTop="12dp" 
       android:text="Fr" android:layout_height="wrap_content" 
       android:textStyle="normal" android:textColor="#7e7f7e" 
       android:layout_width="63px"> 
      </TextView> 
      <TextView android:typeface="sans" android:layout_marginTop="12dp" 
       android:paddingLeft="5dp" android:text="Sa" android:layout_height="wrap_content" 
       android:textStyle="normal" android:textColor="#7e7f7e" 
       android:layout_width="63px"> 
      </TextView> 
     </LinearLayout> 
     <GridView android:numColumns="7" android:layout_marginTop="5dp" style="overflow:lock" 
      android:layout_marginBottom="10dp" android:layout_width="fill_parent" 
      android:layout_height="wrap_content" android:id="@+id/calendar" 
      android:horizontalSpacing="-1px" android:verticalSpacing="-1px" 
      android:layout_marginLeft="2dp" android:isScrollContainer="false" 
      android:smoothScrollbar="false" android:stackFromBottom="false" 
      android:fastScrollEnabled="false" android:stretchMode="columnWidth" android:fadeScrollbars="false"> 
     </GridView> 
    </LinearLayout> 
</RelativeLayout> 
+0

こんにちは!レイアウトを投稿できますか? – Otra

+0

オトラは私がこれをしたのを見てください。 –

+0

@PoojaBohora私は同じ問題に直面しています。どのような解決策がありますか? –

答えて

1

GridView私のレイアウトでは、垂直方向にスクロールするように設計され、私はあなたがスクロールからそれを止めることができることを認識していないですしています。スクロールしたくない場合は、GridViewを使用しないでください。

+0

しかし、私たちは何よりも使うべきですか? 私は画面上のどこかにそれぞれ1文字しか入っていない8 * 8平方フィールドのグリッドに合わせたいと思っています。何を使うべきですか? – Ewoks

+0

@Ewoks: 'TableLayout'、ネストされた' LinearLayouts'を使うか、好みのビジネスルールを実装する独自の 'ViewGroup'を作成してください。 – CommonsWare

6

その後、onTouch方法であなたはGridViewのスクロールではないにするために、このようなコードを使用することができ、GridViewのためsetOnTouchListenerを追加したり、上書きしよう:

gridview.setOnTouchListener(new OnTouchListener(){ 

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

}); 
+0

このソリューションは上記の問題を解決しますが、新しいものを作成します。指を離してもボタンの押下をキャンセルすることはできません。つまり、グリッドの左下にあるボタンをタッチして右上にスライドさせると、指を動かさないかのように、左下のボタンが上がったときにonClickを呼び出します。ドラッグしている間も、ボタンは押された状態のままです。 – SilithCrowe

0
public class myGridView extends GridView { 

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

    @Override 
    public boolean onTouchEvent(MotionEvent event) { 

    switch(event.getAction()){ 

    case MotionEvent.ACTION_DOWN: 
    return super.onTouchEvent(event); 

    case MotionEvent.ACTION_MOVE: 
    //Do nothing here!!! 
    break; 

    case MotionEvent.ACTION_UP: 
    return super.onTouchEvent(event); 
    } 

    //false return 
    return false; 
    } 
} 
+0

コードには説明が必要です。 –

3

を使用し、このカスタムGridViewコントロール。それは自動的に高さを設定し、スクロールしません:

public class MyGridView extends GridView { 
    public MyGridView(Context context) { 
     super(context); 
    } 

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

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

    @Override 
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { 
     int heightSpec; 

     if (getLayoutParams().height == LayoutParams.WRAP_CONTENT) { 
      // The great Android "hackatlon", the love, the magic. 
      // The two leftmost bits in the height measure spec have 
      // a special meaning, hence we can't use them to describe height. 
      heightSpec = MeasureSpec.makeMeasureSpec(Integer.MAX_VALUE >> 2, MeasureSpec.AT_MOST); 
     } else { 
      heightSpec = heightMeasureSpec; 
     } 

     super.onMeasure(widthMeasureSpec, heightSpec); 
    } 
} 
関連する問題