2013-06-04 16 views
11

ViewPager'ımda, LinearLayout'a göre bir ImageButton ve TextView tutucusu vardı ve şimdi bunları bir TextView ile değiştirilebilir., TextView (android: gravity = "center" ile) öğesine dokunduğunuzda ViewPager'ı görüntüleyemez (0: android).

<?xml version="1.0" encoding="utf-8"?> 
<com.iclinux.android.custom_views.NoScrollTextView 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:iclinux="http://schemas.android.com/apk/res-auto" 
    android:clipChildren="false" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:singleLine="true" 
    android:gravity="center" 
    android:paddingLeft="8dp" 
    android:paddingRight="8dp" 
    android:drawableTop="@drawable/icon_bg" 
    style="@style/EllipsizedSingleLineTextView" 
    android:textSize="@dimen/grid_item_title_size" 
    > 
</com.iclinux.android.custom_views.NoScrollTextView> 

Sorum şu: Ben sola veya sağa TextView dokunurken, ama kaldırıldı "android: yerçekimi =" eğer dokunamazsınız merkezi", çalışıyor ... ne yazık ki, metin zaten merkezli değil .. .? burada ne

public class NoScrollTextView extends TextView { 

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

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

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

    @Override 
    public boolean onTouchEvent(MotionEvent event) { 
     if (event.getAction() == MotionEvent.ACTION_MOVE) 
      return false; 
     return super.onTouchEvent(event); 
    } 
} 

çok teşekkürler

+0

Ben elçi gelip İlginç böcek. Teşekkür ederim. Sana oy verdim. – tasomaniac

+1

Sadece aynı sorun, cevabı bulundu [burada] (http://stackoverflow.com/questions/15470755/textview-inside-viewpager-intercepts-touch-events) – darktiny

cevap

9

geçersiz kılarak çözüldü.

@TargetApi(14) 
@Override 
public boolean canScrollHorizontally(int direction) { 
    return false; 
} 
16

android:singleLine="true" kuvvetler android:scrollHorizontally true olarak ayarlanır ve android:gravity (yani değiştirmek yalnızca benim testlere göre edilecek varsayılan yerçekimi bu problemi vermez gibi görünüyor).

Ben sadece bu değişiklikten sonra android:maxLines="1"

ile android:singleLine="true" değiştirerek TextView bu sorunu çözmüş, ben ViewPager ile daha fazla sorun vardı. Şimdi android:gravity="right" ile elemanlara dokunurken beklendiği gibi ilerliyor.

+0

OMG! Böyle aptalca bir problemin iki saatini harcadım ve sonunda cevabını buldum. Google'ın bu boktan böcekleri koyduğuna inanamıyorum. –

+1

OMG! Bu kısaca Android. – milosmns

1

Ben yaparak bitti:

textView.setHorizontallyScrolling(false); 
İlgili konular