我有以下布局
<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
但结果相同。
答案 0 :(得分:26)
您可以尝试让LinearLayout
实现onClick
属性,然后设置:
android:fillViewport="true"
到ScrollView
。
答案 1 :(得分:0)
我有一个类似的问题,只是摆脱了scrollview本身。相反,我直接插入TextView本身,使用先前放在ScrollView上的约束。我的ScrollView的整个目的是在TextView中滚动,而不是在几个项目中滚动,所以它似乎是一种更优雅的方式。
将(垂直)滚动条添加到activity.hmtl中的textview:
<TextView
android:id="@+id/tvInfo"
(...)
android:scrollbars="vertical"
/>
将其添加到onCreate方法:
oTV = (TextView) findViewById(R.id.tvInfo);
oTV.setMovementMethod(new ScrollingMovementMethod());
无需编写滚动响应。我喜欢那样。
我在这里找到了解决方案(thx Juned Mughal):
http://www.android-examples.com/make-textview-scrollable-in-android-programmatically/
答案 2 :(得分:-1)
要使滚动视图填满屏幕更改:
<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();
}
});