【发布时间】:2012-12-10 20:21:48
【问题描述】:
我想知道我是否正确设置了 TouchDelegate。我想增加我的 LinearLayout 中 TextViews 的触摸区域。
我的布局是这样的。
<LinearLayout
android:id="@+id/subcategory"
android:layout_width="fill_parent"
android:layout_height="35dp"
android:background="#000000"
android:gravity="center_horizontal"
android:orientation="horizontal"
android:padding="5dp" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="All"
android:textColor="#FFFFFF"
android:textSize="18sp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingRight="30dp"
android:text="None"
android:textColor="#FFFFFF"
android:textSize="18sp" />
</LinearLayout>
我从 onActivityCreated() 调用以下内容,其中 subCategoryLayout 是 LinearLayout
subCategoryLayout.post(new Runnable() {
@Override
public void run() {
for (int i = 0; i < subCategoryLayout.getChildCount(); i++) {
Rect delegateArea = new Rect();
TextView d = (TextView) subCategoryLayout.getChildAt(i);
d.getHitRect(delegateArea);
delegateArea.bottom += 50;
delegateArea.top += 200;
delegateArea.left += 50;
delegateArea.right += 50;
TouchDelegate expandedArea = new TouchDelegate(delegateArea, d);
subCategoryLayout.setTouchDelegate(expandedArea);
// if (View.class.isInstance(d.getParent())) {
// ((View) d.getParent()).setTouchDelegate(expandedArea);
// }
}
}
});
【问题讨论】:
-
您的问题解决了吗?我也有同样的问题。
-
使用触摸代理实际上并没有增加触摸区域
标签: android android-linearlayout textview