1.6, 2.2 및 MyTouch 3G Slide (API # 7이며 Android Device Chooser에서 "2.1-Update1"로 표시됨)에서이 이상한 문제가 발생했습니다. 누구나 내가 뭘 잘못하고 있는지 설명 할 수 있다면 그것을 수정하는 방법 (또는 아마도 이것이 안드로이드 버그인지 확인하는 것), 나는 그것을 크게 고맙게 여길 것이다!TextView.setText가 스크롤링 할 ScrollView를 둘러싸고있는 이유는 무엇입니까?
내 앱의 기본 아이디어는 타이머를 시작하기 위해 버튼을 탭한 다음 다시 한 번 눌러 타이머를 중지 (일시 중지) 할 수 있다는 점에서 스톱워치를 정렬하는 것입니다. 타이머를 다시 시작하고 타이머를 일시 중지하는 사이에 다른 탭이 번갈아 표시됩니다.
위젯이 많이 포함 된 RelativelLayout이 포함 된 최상위 ScrollView가 있습니다. 첫 번째 위젯은 화면 아래쪽에있는 다른 모든 위젯을 푸시하는 거대한 버튼입니다 (누르기 쉽습니다). 이는 ScrollView (및 사용자에게 화면상의 알림)를 사용하여 나머지 입력 옵션을 사용할 수있게하려는 의도로 의도적 인 것입니다.
간단한 상태 시스템 유형 설정이 있습니다. 여기서 mState는 현재 모드입니다 (사용자가 아무 버튼이나 누르기 전에 STATE_TIMER_NOT_STARTED ... 첫 번째 누른 후 실행 후 ... 두 번째 이후에 PAUSED, 다시 ... 세 번째 이후에 실행 등).
이 모든 기능은 타이머가 실행 중일 때 사용자가 시작/중지/다시 시작 버튼을 다시 누르면 스크롤 방법이 아래로 스크롤됩니다. 나는이 명령을 내리지 않고있다. (나는 ScrollView 객체에 대한 참조조차 없다.) 왜 이런 일을하는지 모르겠다.
REPRO : 다음 샘플을 컴파일 + 실행하십시오. 앱이 시작되면 '시작 타이밍'버튼을 누릅니다. 엄지 (또는 마우스)를 사용하여 화면을 위쪽으로 터치 드래그하여 (그러면 RatingBar를 볼 수 있습니다.) 그런 다음 다시 아래로 드래그하십시오 (그러면 버튼이 완전히 화면에 나타납니다). 버튼을 탭하면 (다시 '일시 정지'라고 읽음) 조금 아래로 넘어갑니다. 스크롤하지 말라고 말하는 문장이 없기 때문에 점프/스크롤 다운해서는 안됩니다. 내가 말할 수있는 한 가까이에서 스크롤을 발생시키는 것은 setText입니다 (해당 행을 주석 처리 할 때 스크롤이 발생하지 않음).
내가 무엇을 요구하는지 : 만약 내가 뭔가 바보가되고 있다면 & 당신은 그것이 무엇인지를 지적 할 수있다. 나는 그것을 정말로 고맙게 생각한다! :) *** '터치 모드'가 패널과 위쪽을 이동할 때 마우스의 스크롤 휠을 사용할 때 (에뮬레이터에서) 나타나지 않기 때문에이 작업과 관련이 있을지 궁금합니다 (예 : 시뮬레이션 된 핑거 드래그). 나는 터치 모드에서 전체를 찾을 수없고, ScrollView 내에서 터치 모드의 초점/선택에 특별한 것을 찾을 수 없다.
이 오류가 발생했음을 확인할 수 있다면 역시 괜찮을 것이다. 불행은 회사를 사랑합니다. AHEM 내 말은, 그것이 나만의 것이 아닌지 확인하는 데 도움이되기 때문입니다. :)).
MyTestApp.java
package bug.android.scrollview;
import android.app.Activity;
import android.os.Bundle;
import android.text.format.Time;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.TextView;
public class MyTestApp extends Activity {
public final static int STATE_TIMER_NOT_STARTED = 1;
public final static int STATE_TIMER_RUNNING = 2;
public final static int STATE_TIMER_PAUSED = 3;
private int mState;
Time t = new Time();
private Time data = new Time();
private Button btnStartStopResume;
private TextView lblSpacer;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_time_entry);
btnStartStopResume = (Button) findViewById(R.id.btnStartStopResume);
// Set the button's size so that the other info will also be visible
Display display = ((WindowManager) getSystemService(WINDOW_SERVICE))
.getDefaultDisplay();
// This is such a hack, but the windowScroller doesn't appear to
// have a height at this point in the lifecycle (nor in 'onResume' :()
btnStartStopResume.setHeight(display.getHeight() - 200);
lblSpacer = (TextView) findViewById(R.id.lblSpacer);
reset();
}
public void doStartStopResume(View v) {
if (mState == MyTestApp.STATE_TIMER_NOT_STARTED) {
mState = MyTestApp.STATE_TIMER_RUNNING;
data.setToNow();
} else if (mState == MyTestApp.STATE_TIMER_RUNNING) {
mState = MyTestApp.STATE_TIMER_PAUSED;
String s = getString(R.string.add_scroll_down_to_add);
lblSpacer.setText(s);
} else if (mState == MyTestApp.STATE_TIMER_PAUSED) {
mState = MyTestApp.STATE_TIMER_RUNNING;
}
}
public void doReset(View v) {
}
public void doNewRunClick(View v) {
}
public void doAddTiming(View v) {
}
public void reset() {
mState = STATE_TIMER_NOT_STARTED;
}
}
new_time_entry.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/windowScroller"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<RelativeLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<Button
android:id="@+id/btnStartStopResume"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="5dip"
android:text="Start Timing"
android:textSize="40dp"
android:height="290dp"
android:onClick="doStartStopResume" />
<TextView
android:id="@+id/lblSpacer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/btnStartStopResume"
android:layout_centerHorizontal="true"
android:text="@string/add_scroll_down_for_more" />
<TextView
android:id="@+id/lblTimeStartLabel"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lblSpacer"
android:layout_alignParentLeft="true"
android:clickable="true"
android:onClick="adjustStartTime"
android:text="Start of this run:"
android:textSize="8dp" />
<TextView
android:id="@+id/lblTimeStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lblTimeStartLabel"
android:layout_alignParentLeft="true"
android:clickable="true"
android:onClick="adjustStartTime"
android:text="--:--:-- --"
android:textColor="#FFFFFF"
android:textSize="26dp" />
<TextView
android:id="@+id/lblElapsedLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lblSpacer"
android:layout_alignRight="@id/lblSpacer"
android:layout_marginRight="5dp"
android:text="Elapsed Time:"
android:textSize="8dp" />
<TextView
android:id="@+id/lblTimeElapsed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lblElapsedLabel"
android:layout_alignRight="@id/lblSpacer"
android:layout_marginRight="5dp"
android:textColor="#99ff66"
android:text="-- m -- sec"
android:textSize="26dp"
android:layout_marginBottom="10dip"/>
<CheckBox
android:id="@+id/chkNewRun"
android:onClick="doNewRunClick"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lblTimeElapsed"
android:text="This is a new run of timings"
android:layout_marginBottom="10dip" />
<TextView
android:id="@+id/lblIntensity"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Intensity (1 = none 5 = max)"
android:layout_below="@id/chkNewRun" />
<RatingBar
android:id="@+id/rbIntensity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/lblIntensity"
android:numStars="5"
android:rating="2"
android:layout_marginBottom="5dip" />
<TextView
android:id="@+id/lblNotes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Notes:"
android:layout_below="@id/rbIntensity" />
<EditText
android:id="@+id/txtNotes"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:drawable/editbox_background"
android:layout_below="@id/lblNotes"
android:layout_marginBottom="10dip" />
<Button
android:id="@+id/btnReset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtNotes"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:text="Reset"
android:onClick="doReset" />
<Button
android:id="@+id/btnOk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/txtNotes"
android:layout_toRightOf="@id/btnReset"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dip"
android:layout_marginRight="10dip"
android:text="Add Timing To List"
android:onClick="doAddTiming" />
</RelativeLayout>
</ScrollView>
strings.xml의
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="app_name">Timer</string>
<string name="dlg_edit_timing_title">Edit A Timing</string>
<string name="add_scroll_down_for_more">< Scroll down for more options! ></string>
<string name="add_scroll_down_to_add">< Scroll down to save this timing! ></string>
<string name="start_timing">Start Timing\n\n</string>
<string name="stop_timing">Pause Timing\n\n</string>
<string name="resume_timing">Resume Timing\n\n</string>
</resources>
droidManifest.XML
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="bug.android.scrollview"
android:versionCode="1"
android:versionName="1.0">
<application android:icon="@drawable/icon" android:label="@string/app_name">
<activity android:name=".MyTestApp"
android:label="@string/app_name">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-sdk android:minSdkVersion="5" />
</manifest>
UPDATE 1 : 디버거에서
if( btnStartStopResume.isInTouchMode())
Toast.makeText(this, "TOUCH MODE", 2000);
else
Toast.makeText(this, "NOT touch mode", 2000);
다음 설정 중단 점을 추가 버튼에 관계없이 I 손가락 드래그 여부 패널 (터치 모드에서 항상 위/아래, 이상인지 확인 마우스 휠 위/아래). 따라서 두 번째 버튼을 누른 후 (즉, 앱이 '중지/일시 중지 된 타이밍'모드에있을 때) 패널을 터치 모드로 드래그하여 뒤틀린 상태에서 이상한 타이밍을 유발하는 조합입니다.
업데이트 2 : 나는 단지 그것이 EditText로 스크롤되는 것을 알아 차 렸습니다. 패널을 아래로 움직이면 EditText가 선택 항목을 얻고 Click 이벤트 후에 ScrollView는 선택 항목이있는 항목으로 다시 스크롤하는 것처럼 보입니다. 마우스 휠 접근 방식에이 문제가없는 이유를 설명합니다 (선택/포커스를 버튼으로 다시 이동시킵니다).
http://stackoverflow.com/questions/5375838/scrollview-disable-focus-move/7114179 # 7114179 – yanchenko