求解?Android自定义下拉,为什么只能获取到第一个控件的焦点了

我定义了一个下拉效果。但是只点击了他下面第一个控件才有效:

我点击或者触摸“这里是彩期显示区域”才会下拉出历史记录。我现在想要点击下面的红球、篮球选球区域也有效,怎么修改????

java代码:

package com.example.testxiala;

import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {
	private Scrllon_view scrllon_view;
	private TextView lisi_textview;
	private TextView main_textview;
	private TextView main_textview2;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);

		scrllon_view = (Scrllon_view) findViewById(R.id.main_relative_scrllon_view);
		lisi_textview = (TextView) findViewById(R.id.lisi_textiview);
		main_textview = (TextView) findViewById(R.id.main_textiview1);
		main_textview2 = (TextView) findViewById(R.id.main_textiview2); 

		scrllon_view.setMaxHeight(100);
	}

}

xml布局代码:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#f6f6f6"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="52dip"
        android:layout_gravity="center"
        android:background="#d80702" >

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:gravity="center"
            android:paddingLeft="15dip"
            android:text="双色球-普通"
            android:textColor="#ffffff"
            android:textSize="18sp" />
    </RelativeLayout>

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="0dip"
        android:layout_weight="1"
        android:background="#f6f6f6"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/lisi_textiview"
            android:layout_width="fill_parent"
            android:layout_height="80dip"
            android:background="#517688"
            android:gravity="center"
            android:text="历史记录"
            android:visibility="visible" />

        <com.example.testxiala.Scrllon_view
            android:id="@+id/main_relative_scrllon_view"
            android:layout_width="match_parent"
            android:layout_height="fill_parent" >

            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="#7d7d7d"
                android:focusable="true"
                android:orientation="vertical" >

                <TextView
                    android:id="@+id/main_textiview"
                    android:layout_width="fill_parent"
                    android:layout_height="40dip"
                    android:background="#aabbcc"
                    android:gravity="center"
                    android:text="这里是彩期显示区域"
                    android:textColor="#222222"
                    android:visibility="visible" />

                <TextView
                    android:id="@+id/main_textiview1"
                    android:layout_width="fill_parent"
                    android:layout_height="200dip"
                    android:background="#cbacba"
                    android:gravity="center"
                    android:text="这里是选球界面,红球"
                    android:textColor="#d80702"
                    android:visibility="visible" />

                <TextView
                    android:id="@+id/main_textiview2"
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:background="#abcabc"
                    android:gravity="center"
                    android:text="这里是选球界面,篮球"
                    android:textColor="#d80702"
                    android:visibility="visible" />
            </LinearLayout>
        </com.example.testxiala.Scrllon_view>
    </RelativeLayout>

    <!-- 金额,确认选号 -->

    <View
        android:layout_width="fill_parent"
        android:layout_height="1px"
        android:background="#dedede" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="52dip"
        android:background="#f8f8f8"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/ssq_main_txt_mainConfirm"
            android:layout_width="80dp"
            android:layout_height="36dp"
            android:layout_alignParentRight="true"
            android:layout_centerVertical="true"
            android:layout_marginRight="10dp"
            android:gravity="center"
            android:text="投注"
            android:textColor="#222222"
            android:textSize="16sp"
            android:textStyle="bold"
            android:typeface="monospace" />
    </RelativeLayout>

</LinearLayout>

还有我自定义的Scrllon_view

package com.example.testxiala;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.widget.LinearLayout;
import android.widget.Scroller;

/**
 * LinearLayout换成RelativeLayout效果也是一样
 */
public class Scrllon_view extends LinearLayout {
	Scroller croller;

	private int moveY = 0;
	public boolean mEnabled = true;
	public int maxHeight = 0;

	public int getMaxHeight() {
		return maxHeight;
	}

	public void setMaxHeight(int maxHeight) {
		this.maxHeight = maxHeight;
	}

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

	public Scrllon_view(Context context, AttributeSet set) {
		super(context, set);
		setDescendantFocusability(FOCUS_AFTER_DESCENDANTS);
		setFocusable(true);
		croller = new Scroller(context);

	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		switch (event.getAction()) {
		case MotionEvent.ACTION_DOWN:
			return true;
		case MotionEvent.ACTION_MOVE:

			moveY = (int) event.getY();
			int Y = moveY;
			if (Y < maxHeight && moveY > 0) {
				scrollTo(0, -moveY);
			}
			break;
		case MotionEvent.ACTION_UP:
			int YY = (int) event.getY();
			if (YY < 100) {
				scrollTo(0, 0);
			} else if (YY > 250 && YY < maxHeight) {
				scrollTo(0, -(maxHeight));
			}
			break;
		default:
			break;
		}
		return super.onTouchEvent(event);
	}

	public void startMoveAnim(int startY, int dy, int duration) {
		croller.startScroll(100, startY, 100, dy, duration);
	}

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

}

代码全部在上面,求解???

时间: 2024-07-31 03:29:22

求解?Android自定义下拉,为什么只能获取到第一个控件的焦点了的相关文章

Android自定义下拉刷新动画--仿百度外卖下拉刷新

好久没写博客了,小编之前一段时间一直在找工作,从天津来到了我们的大帝都,感觉还不错.好了废话不多说了,开始我们今天的主题吧.现如今的APP各式各样,同样也带来了各种需求,一个下拉刷新都能玩出花样了,前两天订饭的时候不经意间看到了"百度外卖"的下拉刷新,今天的主题就是它–自定义下拉刷新动画. 看一下实现效果吧: 动画 我们先来看看Android中的动画吧: Android中的动画分为三种: Tween动画,这一类的动画提供了旋转.平移.缩放等效果. Alpha – 淡入淡出 Scale

Android 自定义下拉刷新ExpandableListView

自定义下拉刷新ExpandableListView,在本文的demo中做的是好友分组列表,可以通过下拉刷新数据.自定义控件是继承了ExpandableListView这个类,接口就是OnScrollListener这样来实现的.接下看看怎样调用这个自定义控件.先看效果图. 本文源码下载:点击 一.实现的效果图 二.看自定义控制类XExpandableListView package com.org.xlistview; import com.example.pullrefresh.R; impo

Android 自定义下拉框的实现 Spinner

下拉框布局  a_spinner_checked_text.xml <?xml version="1.0" encoding="utf-8"?><CheckedTextView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@android:id/text1" android:layout_width="

Android之——自定义下拉菜单的实现

转载请注明出处:http://blog.csdn.net/l1028386804/article/details/48101651 做过Android开发的童鞋,一般都会遇到这样一种情况,就是Android中原有的下拉控件Spinner过于单调和简单,不能够满足我们实际开发的需求了,这时候就需要我们自己自定义下拉菜单来实现相应的功能,那么,如何实现自定义下拉菜单呢?下面我就来和大家一起实现这个功能. 一.原理 我们这个下拉菜单展示的内容主要以ListView实现,在界面上放置一个文本框,文本框右

Android自定义组合控件---教你如何自定义下拉刷新和左滑删除

绪论 最近项目里面用到了下拉刷新和左滑删除,网上找了找并没有可以用的,有比较好的左滑删除,但是并没有和下拉刷新上拉加载结合到一起,要不就是一些比较水的结合,并不能在项目里面使用,小编一着急自己组合了一个,做完了和QQ的对比了一下,并没有太大区别,今天分享给大家,其实并不难,但是不知道为什么网上没有比较好的Demo,当你的项目真的很急的时候,又没有比较好的Demo,那么"那条友谊的小船儿真是说翻就翻啊",好了,下面先来具体看一下实现后的效果吧: 代码已经上传到Github上了,小伙伴们记

Android中自定义下拉样式Spinner

Android中自定义下拉样式Spinner 本文继续介绍android自定义控件系列,自定义Spinner控件的使用. 实现思路 1.定义下拉控件布局(ListView及子控件布局) 2.自定义SpinerPopWindow类 3.定义填充数据的Adapter 效果图 一.定义控件布局 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http:/

Android UI- PullToRrefresh自定义下拉刷新动画

Android UI- PullToRrefresh自定义下拉刷新动画 如果觉得本文不错,麻烦投一票,2014年博客之星投票地址:http://vote.blog.csdn.net/blogstar2014/details?username=wwj_748#content 本篇博文要给大家分享的是如何使用修改开源项目PullToRrefresh下拉刷新的动画,来满足我们开发当中特定的需求,我们比较常见的一种下拉刷新样式可能是以下这种: 就是下拉列表的时候两个箭头上下翻转,更改日期文本和刷新状态,

android中自定义下拉框(转)

android自带的下拉框好用不?我觉得有时候好用,有时候难有,项目规定这样的效果,自带的控件实现不了,那么只有我们自己来老老实实滴写一个新的了,其实最基本的下拉框就像一些资料填写时,点击的时候出现在编辑框的下面,然后又很多选项的下拉框,可是我在网上找了一下,没有这种下拉框额,就自己写了一个,看效果图先: ,这个是资料填写的一部分界面,三个下拉框,选择故乡所在地: 点击之后弹出下拉框,选择下面的选项: 三个下拉框时关联的,第一个决定了第二数据内容,第二个决定了第三个数据内容,如果三个全部选好之后

Android PullToRrefresh 自定义下拉刷新动画 (listview、scrollview等)

PullToRefreshScrollView 自定义下拉刷新动画,只需改一处. 以下部分转载自http://blog.csdn.net/superjunjin/article/details/45022595 一,定义刷新动画的layout 在library下的com.handmark.pulltorefresh.library.internal包中的FlipLoadingLayout和RotateLoadingLayout FlipLoadingLayout为ios风格的箭头颠倒的刷新动画