查看屏幕中的中心视图

时间:2016-08-27 13:53:06

标签: android xml view scrollview

我正在搜索整个网络,但我没有看到有人问这个: 您好scroolview,我需要view在查看的屏幕中居中,我的意思是: 我设置了一个gravity:center attribute,但当scrollview变得更长时view不再可见,因为它位于scrollview的中心,而不是view电话屏幕。如何将<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

friend std::ostream& operator<< <>(std ::ostream& out, Array1D<T>& a);

1 个答案:

答案 0 :(得分:-1)

试试这个

   <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
    <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">



        </FrameLayout>

    </ScrollView>
     <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:layout_centerInParent="true"
                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>
</RelativeLayout>