簡體   English   中英

Android在翻譯Y時保持視圖底部固定

[英]Android Keep view's bottom fixed while translating it's Y

我有一個填滿我屏幕的視圖,我正在為其Y設置動畫,因此它的頂部被隱藏了, 但是我需要它的按鈕保持它的位置。

動畫代碼:

mainLayout.animate().translationY(-toolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).start();

滾動之前:

在此處輸入圖片說明

滾動后:

在此處輸入圖片說明

注意:

1)我這樣做是因為我需要在滾動條上隱藏工具欄。

2)我嘗試了其他隱藏工具欄的方法,包括設置工具欄的高度,邊距,內邊距等,但是它們像地獄一樣漫長。

3)我試圖翻譯工具欄,但它在布局下方,保持其位置,並且不會向上移動。

更新1:

<android.support.v4.widget.DrawerLayout
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/home_drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    tools:context=".HomeActivity"
    android:cacheColorHint="@android:color/transparent"
    android:clipToPadding="false"
    >

    <!-- main view -->
    <RelativeLayout
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/tansparent"
        android:id="@+id/home_main_layout"
        tools:context=".HomeActivity">

        <android.support.v7.widget.Toolbar xmlns:app="http://schemas.android.com/apk/res-auto"
                                           android:id="@+id/home_toolbar"
                                           android:layout_width="match_parent"
                                           android:layout_height="?attr/actionBarSize"
                                           android:background="@color/category_activity_topbar_background"
                                           app:theme="@style/Theme.AppCompat"
                                           android:layout_alignParentTop="true"/>

        <com.viewpagerindicator.TabPageIndicator
            android:id="@+id/tab_indicator"
            android:layout_height="@dimen/tab_height"
            android:layout_width="match_parent"
            android:layout_below="@+id/home_toolbar"/>

        <android.support.v4.view.ViewPager
            android:id="@+id/home_pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@id/tab_indicator"/>

        <ImageButton
            android:id="@+id/addBookButton"
            android:layout_width="@dimen/add_button_width_height"
            android:layout_height="@dimen/add_button_width_height"
            android:scaleType="centerInside"
            android:src="@drawable/add_button"
            android:background="@drawable/circles_background"
            android:adjustViewBounds="true"
            android:layout_alignParentBottom="true"
            android:layout_alignParentRight="true"
            android:layout_marginBottom="@dimen/add_button_margin_bottom"
            android:layout_marginRight="@dimen/add_button_margin_right"
            android:onClick="importNewBooksButtonMethod"/>

    </RelativeLayout>

    <!-- drawer -->
    <LinearLayout
        android:id="@+id/settingDrawer"
        android:layout_width="@dimen/setting_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:orientation="vertical"
        android:background="@color/white"
        android:clickable="true">
    </LinearLayout>
</android.support.v4.widget.DrawerLayout>

好的,我對整個視圖進行了動畫處理,然后將視圖的邊距設置為負值。 工具欄變得隱藏起來,一切正常進行。

homeMainLayout.animate().translationY(-toolbar.getBottom()).setInterpolator(new AccelerateInterpolator()).withEndAction(new Runnable()
            {
                @Override
                public void run()
                {
                    DrawerLayout.LayoutParams params = (DrawerLayout.LayoutParams) homeMainLayout.getLayoutParams();
                    params.bottomMargin = -toolbarHeight;
                    homeMainLayout.setLayoutParams(params);
                }
            }).start();

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM