May*_*ynn 34 xml android scrollview
当我启动模拟器并进入使用此代码的屏幕时,它会显示大部分文本信息,但会切断屏幕顶部(无法向上滚动),但会在底部留下一些空间.
这是代码;
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible"
android:fillViewport="true"
android:id="@+id/backgroundImage" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:padding="10dip" >
<ImageView
android:id="@+id/earthSymbolImageView"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/earthsymbol" />
<TextView
android:id="@+id/earth_content1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/earth_title"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<TextView
android:id="@+id/earth_content2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/earth_text"
android:textColor="#FFFFFF" />
<Button
android:id="@+id/backButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/back" />
</LinearLayout>
</ScrollView>
Run Code Online (Sandbox Code Playgroud)
有谁知道为什么会这样?
Dav*_*idR 39
这是由于LinearLayout中的layout_gravity引起的.由于您的LinearLayout位于ScrollView内部,因此您可能只是尝试水平居中(因此ScrollView内部垂直居中).将LinearLayout指定为像这样水平居中应该可以解决问题:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center_horizontal"
android:padding="10dip" >
Run Code Online (Sandbox Code Playgroud)
Tre*_*ery 24
我有一个HorizontalScrollView
嵌套在里面的同样的问题ScrollView.
我有HorizontalScrollView
重力设置center
导致问题.只是删除它修复了问题.
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="1000dp"
android:layout_height="1000dp"
android:gravity="center"
android:layout_gravity="center"
android:text="New Text"/>
</LinearLayout>
</HorizontalScrollView>
Run Code Online (Sandbox Code Playgroud)
我找到并测试的最佳答案解决了这个问题,@ hadi在这个问题中给出了一个: 没有引力滚动视图.如何将scrollview中的内容作为中心
恢复答案:
代码是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ScrollView
android:id="@+id/scrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
...
</LinearLayout>
</ScrollView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
小智 -3
如果您希望 TextView 可滚动,为什么不将 ScrollView 放在这两个元素周围呢?
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center"
android:padding="10dip" >
<ScrollView>
<ImageView
android:id="@+id/earthSymbolImageView"
android:layout_width="25dp"
android:layout_height="25dp"
android:src="@drawable/earthsymbol" />
<TextView
android:id="@+id/earth_content1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/earth_title"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="20sp" />
<TextView
android:id="@+id/earth_content2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/earth_text"
android:textColor="#FFFFFF" />
</ScrollView>
<Button
android:id="@+id/backButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/back" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
13469 次 |
最近记录: |