Android ScrollView内部片段不滚动
在我的活动中,我有一个Android ScrollView内部片段不滚动,android,scrollview,Android,Scrollview,在我的活动中,我有一个FrameLayout,它假设用作片段的容器 在我的片段中,我得到了一个没有响应的滚动视图ScrollView包含TextView设置android:layout\u height=“wrap\u content”,其中来自我的java代码的文本明显大于ScrollView的大小 我的xml片段: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://s
FrameLayout
,它假设用作片段的容器
在我的片段中,我得到了一个没有响应的滚动视图ScrollView
包含TextView
设置android:layout\u height=“wrap\u content”
,其中来自我的java代码的文本明显大于ScrollView
的大小
我的xml片段:
<?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">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:layout_width="@dimen/bookview.imageWidth"
android:layout_height="250dp"
android:id="@+id/bookView.image"/>
<TextView
android:textSize="@dimen/custom_book_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_toEndOf="@id/bookView.image"
android:id="@+id/bookView.name"/>
<TextView
android:textSize="@dimen/custom_book_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_toEndOf="@id/bookView.image"
android:layout_below="@id/bookView.name"
android:id="@+id/bookView.author"/>
<TextView
android:textSize="@dimen/custom_book_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_toEndOf="@id/bookView.image"
android:layout_below="@id/bookView.author"
android:id="@+id/bookView.pages"/>
<TextView
android:textSize="@dimen/custom_book_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_toEndOf="@id/bookView.image"
android:layout_below="@id/bookView.pages"
android:id="@+id/bookView.category"/>
<TextView
android:textSize="@dimen/custom_book_text"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:layout_toEndOf="@id/bookView.image"
android:layout_below="@id/bookView.category"
android:id="@+id/bookView.publishingDate"/>
</RelativeLayout>
<ScrollView
android:layout_height="200dp"
android:layout_width="match_parent"
android:layout_gravity="end">
<TextView
android:layout_height="wrap_content"
android:layout_width="match_parent"
android:textSize="@dimen/custom_book_text"
android:id="@+id/bookView.description"/>
</ScrollView>
</LinearLayout>
imageLoader是我编写的一个类,它扩展了AsyncTask,用于从url下载图像,并在准备就绪时更新UI。我假设您能够看到片段的视图
如果是这样,可以尝试以下几点:
将滚动视图设置为fillViewPort=“true”
然后将文本视图设置为与父视图匹配,因为这是滚动视图中的唯一视图。请注意,您应该真正避免使用硬编码的宽度和高度(甚至dp高度)
而不是返回
return inflater.inflate(R.layout.fragment_book_view, container, false);
只需返回原始视图:v
另一点可读性:不是每次都重新分配textview。
做:
编辑:
我已经测试过了&它是有效的
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:fillViewport="true">
<TextView
android:id="@+id/faq_output_answer"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="match_parent" />
</ScrollView>
我认为这个片段的其他部分(文本视图和图像视图)占据了屏幕的所有区域,ScrollView呈现在屏幕外。
我建议您将所有布局放在ScrollView中。
像这样:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/bookView.image"
android:layout_width="@dimen/bookview.imageWidth"
android:layout_height="250dp"/>
<TextView
android:id="@+id/bookView.name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/bookView.image"
android:textSize="@dimen/custom_book_text"/>
<TextView
android:id="@+id/bookView.author"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bookView.name"
android:layout_toEndOf="@id/bookView.image"
android:textSize="@dimen/custom_book_text"/>
<TextView
android:id="@+id/bookView.pages"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bookView.author"
android:layout_toEndOf="@id/bookView.image"
android:textSize="@dimen/custom_book_text"/>
<TextView
android:id="@+id/bookView.category"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bookView.pages"
android:layout_toEndOf="@id/bookView.image"
android:textSize="@dimen/custom_book_text"/>
<TextView
android:id="@+id/bookView.publishingDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bookView.category"
android:layout_toEndOf="@id/bookView.image"
android:textSize="@dimen/custom_book_text"/>
</RelativeLayout>
<TextView
android:id="@+id/bookView.description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/custom_book_text"/>
</LinearLayout>
尝试将空视图作为滚动视图中的最后一项
<View
android:layout_width = "match_parent"
android:layout_height = "50dp" />
这对我很有用。为什么要使用framelayout来处理片段,有什么特殊原因吗?你能发布你的代码吗,截图会更好?尝试使用线性布局或相对布局来代替framelayout。你的文本显然不够长,或者你上面的scrollview小部件占用了更多空间,因此它在UI中不可见。再次检查或张贴您的screenshot@user4349397i只需描述文本视图即可滚动所有其他内容,其他部分的大小为全屏。在小屏幕上你无法处理这个问题!这在小屏幕上是个大麻烦!!您必须选择以下策略之一:-使用两个滚动视图来处理顶部和底部。这两个滚动视图填充所有屏幕区域-使用我上面的建议你能在文本视图中看到文本吗?同时尝试编辑。我检查了你的代码,仍然有同样的反应,当我触摸ScrollView时,我在旁边看到灰色滚动条,但我没有滚动。所以我知道他触发了事件,它应该滚动,因为当我看不到整个文本时,灰色滚动条会变小。
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:fillViewport="true">
<TextView
android:id="@+id/faq_output_answer"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="match_parent" />
</ScrollView>
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="end">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/bookView.image"
android:layout_width="@dimen/bookview.imageWidth"
android:layout_height="250dp"/>
<TextView
android:id="@+id/bookView.name"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toEndOf="@id/bookView.image"
android:textSize="@dimen/custom_book_text"/>
<TextView
android:id="@+id/bookView.author"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bookView.name"
android:layout_toEndOf="@id/bookView.image"
android:textSize="@dimen/custom_book_text"/>
<TextView
android:id="@+id/bookView.pages"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bookView.author"
android:layout_toEndOf="@id/bookView.image"
android:textSize="@dimen/custom_book_text"/>
<TextView
android:id="@+id/bookView.category"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bookView.pages"
android:layout_toEndOf="@id/bookView.image"
android:textSize="@dimen/custom_book_text"/>
<TextView
android:id="@+id/bookView.publishingDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/bookView.category"
android:layout_toEndOf="@id/bookView.image"
android:textSize="@dimen/custom_book_text"/>
</RelativeLayout>
<TextView
android:id="@+id/bookView.description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="@dimen/custom_book_text"/>
</LinearLayout>
<View
android:layout_width = "match_parent"
android:layout_height = "50dp" />