【发布时间】:2016-08-27 13:53:06
【问题描述】:
我在整个网络上搜索,但没有看到有人问这个:
嗨,有一个 scroolview,我需要一个 view 才能在查看的屏幕中居中,我的意思是:
我设置了一个gravity:center attribute,但是当scrollview 变长时,view 不再可见,因为它位于scrollview 的中心,而不是在手机屏幕上。如何使view 以您所看到的屏幕大小居中?
编辑,XML
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#FFEFD5"
android:id="@+id/dialog_layout"
android:clickable="false"
android:visibility="gone">
<EditText
app:layout_widthPercent="75%"
app:layout_heightPercent="12%"
android:id="@+id/testo"
app:layout_marginLeftPercent="9%"
app:layout_marginRightPercent="9%"
android:background="#F5F5F5"
app:layout_marginTopPercent="5%"
android:hint="Please, insert the text for the new button."
android:gravity="center"
android:maxLength="19"/>
<Button
app:layout_widthPercent="75%"
app:layout_heightPercent="12%"
android:layout_below="@id/testo"
app:layout_marginLeftPercent="9%"
app:layout_marginRightPercent="9%"
app:layout_marginBottomPercent="3%"
android:text="Accept"
android:id="@+id/accept"/>
</android.support.percent.PercentRelativeLayout>
</FrameLayout>
</ScrollView>
【问题讨论】:
-
为什么要使用滚动视图?
-
向我们展示相关的xml,否则没有人可以帮助你。
-
@XaverKapeller 已编辑; masoudvali 只是因为我需要它 :)
-
那个 xml 中有很多地方是错误的。您希望哪个视图居中?
-
@XaverKapeller 为什么很多事情都错了?它对我有用;我想将所有
PercentRelativeLayout居中
标签: android xml view scrollview