ScrollView莫名滚动

hztgcl1986 2014-05-16 11:30:48
一个ViewSwitcher,一个HorizontalScrollView,当ViewSwitcher切换内容时(调用showNext())竟然会导致HorizontalScrollView也跟着滚动。


package inspur.hzt.test;

import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ViewSwitcher;

public class HSVActivity extends Activity {

ViewSwitcher switcher;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

setContentView(R.layout.activity_hsv);

switcher = (ViewSwitcher) findViewById(R.id.viewSwitcher1);
//hsv = (HorizontalScrollView) findViewById(R.id.horizontalScrollView1);
}

@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {

if (keyCode == KeyEvent.KEYCODE_DPAD_RIGHT || keyCode == KeyEvent.KEYCODE_DPAD_LEFT) {
View v = getCurrentFocus();
if (v.getId() == R.id.button1 || v.getId() == R.id.button2) {
switcher.showNext(); //这里竟然会导致HorizontalScrollView也跟着滚动,不知道如何解决
return true;
}
}

return super.onKeyDown(keyCode, event);
}

}



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

<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="120dp"
android:layout_height="30dp"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="100dp"
android:fillViewport="true" >

<LinearLayout
android:id="@+id/ll1"
android:layout_width="1680dp"
android:layout_height="match_parent"
android:orientation="horizontal" >

<TextView
android:layout_width="120dp"
android:layout_height="match_parent"
android:focusable="true"
android:text="TextView1"
android:textColor="@color/textview_color"
android:textSize="20sp" >

<requestFocus />
</TextView>

<TextView
android:layout_width="120dp"
android:layout_height="match_parent"
android:focusable="true"
android:text="TextView2"
android:textColor="@color/textview_color"
android:textSize="20sp" />

<TextView
android:layout_width="120dp"
android:layout_height="match_parent"
android:focusable="true"
android:textSize="20sp"
android:textColor="@color/textview_color"
android:text="TextView3" />

</LinearLayout>

</HorizontalScrollView>

<ViewSwitcher
android:id="@+id/viewSwitcher1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="100dp" >

<Button
android:id="@+id/button1"
android:layout_width="120dp"
android:layout_height="100dp"
android:nextFocusLeft="@id/button1"
android:nextFocusRight="@id/button1"
android:text="Button 1" />

<Button
android:id="@+id/button2"
android:layout_width="120dp"
android:layout_height="100dp"
android:nextFocusLeft="@id/button2"
android:nextFocusRight="@id/button2"
android:text="Button 2" />
</ViewSwitcher>

</LinearLayout>
...全文
245 9 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
hztgcl1986 2014-06-25
  • 打赏
  • 举报
回复
hztgcl1986 2014-05-19
  • 打赏
  • 举报
回复
有人知道吗?
哎,真难 2014-05-16
  • 打赏
  • 举报
回复
不是,我的意思你删掉了就知道我说的冲突对不对了,,,
hztgcl1986 2014-05-16
  • 打赏
  • 举报
回复
不能删除HorizontalScrollView,它里面有3个TextView,同时只显示1个TextView,按右键时会再滚动显示第2个、第3个
哎,真难 2014-05-16
  • 打赏
  • 举报
回复
你可以把HorizontalScrollView删除了试试,,,
hztgcl1986 2014-05-16
  • 打赏
  • 举报
回复
HorizontalScrollView与ViewSwitcher是平级关系,没有嵌套。也没有重叠啊,我加了layout_marginTop="100dp"
哎,真难 2014-05-16
  • 打赏
  • 举报
回复
这个我喜欢,两个事件重叠了呗,,,
hztgcl1986 2014-05-16
  • 打赏
  • 举报
回复
不是 <requestFocus /> 的问题,把它删除后问题仍然存在
映映 2014-05-16
  • 打赏
  • 举报
回复
是不是 <requestFocus /> 这个问题啊

80,471

社区成员

发帖
与我相关
我的任务
社区描述
移动平台 Android
androidandroid-studioandroidx 技术论坛(原bbs)
社区管理员
  • Android
  • yechaoa
  • 失落夏天
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧