Android 在片段中使用可滚动文本视图不会';触摸屏幕时不会重新出现
我在一个片段中有一个图像和一个文本视图(分割屏幕)。我的图像在屏幕的上半部分,文本视图在屏幕的下半部分。我需要文本视图是可滚动的。我试着在我的文本视图周围放置一个可滚动的视图,但显示的是全屏,没有滚动条。在阅读了可滚动文本视图之后,我发现它有一个属性,所以我使用了“android:scrollbars=”vertical“。但是,当我触摸屏幕时,滚动条不会出现,即使有更多的文本要显示。我已经实现了一个onTouchListener,以确保触摸屏处于活动状态,但这不会导致滚动条出现。我也读过几次这篇文章:但我不知道我遗漏了什么。是什么导致滚动条显示?当屏幕第一次出现,然后逐渐消失时,它确实会最初显示。当我触摸片段中的文本视图时,我缺少什么使滚动条重新出现 这是我的xml文件:Android 在片段中使用可滚动文本视图不会';触摸屏幕时不会重新出现,android,android-fragments,scrollbar,scrollview,textview,Android,Android Fragments,Scrollbar,Scrollview,Textview,我在一个片段中有一个图像和一个文本视图(分割屏幕)。我的图像在屏幕的上半部分,文本视图在屏幕的下半部分。我需要文本视图是可滚动的。我试着在我的文本视图周围放置一个可滚动的视图,但显示的是全屏,没有滚动条。在阅读了可滚动文本视图之后,我发现它有一个属性,所以我使用了“android:scrollbars=”vertical“。但是,当我触摸屏幕时,滚动条不会出现,即使有更多的文本要显示。我已经实现了一个onTouchListener,以确保触摸屏处于活动状态,但这不会导致滚动条出现。我也读过几次这
<?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:background="@android:color/white"
android:orientation="vertical"
>
<ImageView
android:id="@+id/bio_imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:layout_weight="1"
android:src="@drawable/bio_pic"/>
<TextView
android:id="@+id/bio_TextView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:textSize="18sp"
android:textColor="#000000"
android:scrollbars="vertical"
android:text="@string/bio_html"/>
</LinearLayout>
我为自己的问题找到了解决办法。不确定这是否是最好的解决方案,但效果很好。我使用了3个线性布局:一个主布局,一个用于图像,一个来自文本视图。我用滚动视图包围了文本视图周围的线性布局。希望这对别人有帮助。这看起来很简单,但对于像我这样的新手来说,获得布局、高度、重量和宽度的正确组合是很棘手的 布局如下:
<?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:background="@android:color/white"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<ImageView
android:id="@+id/bio_imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:src="@drawable/bio_pic"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<TextView
android:id="@+id/bio_TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#000000"
android:scrollbars="vertical"
android:text="@string/bio_html"/>
</LinearLayout>
</ScrollView>
</LinearLayout>
我为自己的问题找到了解决方案。不确定这是否是最好的解决方案,但效果很好。我使用了3个线性布局:一个主布局,一个用于图像,一个来自文本视图。我用滚动视图包围了文本视图周围的线性布局。
<?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:background="@android:color/white"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" >
<ImageView
android:id="@+id/bio_imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/black"
android:src="@drawable/bio_pic"/>
</LinearLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<TextView
android:id="@+id/bio_TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="18sp"
android:textColor="#000000"
android:scrollbars="vertical"
android:text="@string/bio_html"/>
</LinearLayout>
</ScrollView>
</LinearLayout>