求解?Android自訂下拉,為什麼只能擷取到第一個控制項的焦點了,android控制項

來源:互聯網
上載者:User

求解?Android自訂下拉,為什麼只能擷取到第一個控制項的焦點了,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;@Overrideprotected 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);}@Overridepublic 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);}@Overridepublic boolean onInterceptTouchEvent(MotionEvent ev) {if (mEnabled)return false;return super.onInterceptTouchEvent(ev);}}


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


聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.