Viv*_*rde 1 android textview android-layout android-linearlayout android-scrollview
我使用此代码将我的布局划分为2个滚动视图
<?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="0px"
android:background="@drawable/ashokb"
android:layout_weight="4" >
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:background="@drawable/flagc">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
<Button
android:id="@+id/button1"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginLeft="-50dp"
android:background="@drawable/ic_menu_share" />
</LinearLayout>
<TextView
android:id="@+id/textView5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Medium Text"
android:textColor="#000000"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0px"
android:background="@drawable/ashokb"
android:layout_weight="1" >
<ScrollView
android:id="@+id/scrollView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:text="Medium Text"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium"
/>
</ScrollView>
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
这显示在GraphicalLayout中
在设备和模拟器中,视图在对话框中变得正确,如我所愿:
问题:如果textview中的文本很小,那么第一个scrollview的行为与预期的一样正常,但如果texview中的文本很大,则即使滚动完成后整个文本也不可见,而是在滚动结束时显示为空白.如本视频所示
在最后点击的项目中看到,第一个scrollview没有完全显示其内容.
我希望你明白这个问题.
任何解决方案?
基本上,您在布局文件中设置了许多不必要的属性.但是您的问题是由您在顶部的android:layout_gravity第一个属性设置引起的:LinearLayoutScrollView
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center">
Run Code Online (Sandbox Code Playgroud)
删除android:layout_gravity="center"将解决您的问题与裁剪内容ScrollView.
顺便说一句:如果它里面的内容小于ScrollView你想要将它放在里面,你应该使用不同的方法.你不想把孩子直接放在里面,ScrollView但你应该ScrollView用它唯一的孩子来填充它并将内容集中在这个孩子的内心.通常你会设置android:layout_height="match_parent"这个LinearLayout和android:gravity="center".但在ScrollView你不能使用这种方法 - ScrollView直接孩子的高度应该始终是wrap_content设置它match_parent不会工作.但是有一个属性ScrollView允许这样的行为,它被称为setFillViewport(boolean fillViewport),你应该将它设置为true,如下所示:
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:gravity="center">
Run Code Online (Sandbox Code Playgroud)
除了以下几行之外ScrollView没有任何意义.它基本上设置一个重力OS这个ScrollView来center的,但因为它的尺寸相匹配的父-它不能被放置在一个中心.
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
Run Code Online (Sandbox Code Playgroud)
BTW.第二个ScrollView不应该android:layout_height有一套wrap_content.请改成它match_parent.
你也应该尝试简化你的布局和属性数量(特别是所有的"重力":)
| 归档时间: |
|
| 查看次数: |
4076 次 |
| 最近记录: |