У меня есть следующий макет
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white" >
<LinearLayout
android:id="@+id/answerMainFrame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@android:color/white"
android:isScrollContainer="true"
android:onClick="toQuestion" >
<ImageView
android:id="@+id/answer_img"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:contentDescription="@string/question_img_cd" />
<TextView
android:id="@+id/answer"
style="@style/Question" />
</LinearLayout>
Иногда ScrollView
слишком мал и не заполняет весь экран, но все же я хочу вызвать метод toQuestion()
щелкнув в любом месте экрана.
Я пробовал настройку android:layout_height="wrap_content"
для LinearLayout
и android:onClick="toQuestion"
для ScrollView
но тот же результат.
Вы могли бы попытаться позволить LinearLayout
реализовать onClick
атрибут, а затем установить:
android:fillViewport="true"
в ScrollView
.
У меня была аналогичная проблема, и я просто избавился от самого прокрутки. Вместо этого я непосредственно вставил сам TextView с ограничениями, ранее введенными в ScrollView. Вся цель моего ScrollView состояла в том, чтобы прокручивать в TextView, а не в нескольких элементах, поэтому это казалось более элегантным способом.
Добавьте (вертикальную) полосу прокрутки в мой текстовый вид в activity.hmtl:
<TextView
android:id="@+id/tvInfo"
(...)
android:scrollbars="vertical"
/>
Добавьте это в метод onCreate:
oTV = (TextView) findViewById(R.id.tvInfo);
oTV.setMovementMethod(new ScrollingMovementMethod());
Не нужно писать отклик прокрутки. Мне нравится это.
Я нашел решение здесь (спасибо Juned Mughal):
http://www.android-examples.com/make-textview-scrollable-in-android-programmatically/
Чтобы просмотреть прокрутку, измените экран:
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="@android:color/white" >
в
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="@android:color/white" >
и для щелчка поместите это в свой метод onCreate:
((ScrollView) findViewById(R.id.scrollView))
.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
toQuestion();
}
});