2

動画を見て気にならない方は

http://www.youtube.com/watch?v=kWFsmeBJ4l0

親を持つレイアウトがあります: 相対レイアウト、子として 3 つの線形レイアウト: タイトル、メニュー、およびコンテンツ。メニューは作成時に GONE になるように操作され、特定のイベントの後に Visible になり、イベントの反対の後に再び GONE になります。問題は、GONE VISIBLE GONE の最初のサイクルの後、GONE をもう一度実行すると UI が台無しになり、コンテンツがメニューと重なってしまうことです。誰が何が起こったのか教えてもらえますか?

これはレイアウトのコードです

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/metro_dark_blue"
    android:clipChildren="true" >

    <LinearLayout
        android:id="@+id/titleBar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/header_gradient"
        android:orientation="horizontal"
         >

        <LinearLayout
            android:id="@+id/collaborationButton"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:background="@drawable/collaboration_button_xml"
            android:clickable="true" >
        </LinearLayout>
    </LinearLayout>

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBottom="@+id/titleBar"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:background="@null"
        android:gravity="center_vertical"
        android:text="@string/presento"
        android:textSize="25dp" />

    <LinearLayout
        android:id="@+id/connectButton"
        android:layout_width="50dp"
        android:layout_height="50dp"
        android:layout_alignBottom="@+id/titleBar"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="true"
        android:background="@drawable/connect_button_xml"
        android:clickable="true" >
    </LinearLayout>

    <View
        android:id="@+id/titleDropShadow"
        android:layout_width="match_parent"
        android:layout_height="3dp"
        android:layout_alignParentLeft="true"
        android:layout_below="@+id/titleBar"
        android:background="@drawable/drop_shadow"
        android:orientation="horizontal" />

    <LinearLayout
        android:id="@+id/menuBar"
        android:layout_width="match_parent"
        android:layout_height="65dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_below="@+id/titleDropShadow"
        android:background="@drawable/header_gradient"
        android:baselineAligned="true"
        android:visibility="visible" >

        <LinearLayout
            android:id="@+id/remote_button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="0.50"
            android:background="@drawable/menu_button_xml"
            android:clickable="true"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/imageView_remote"
                android:layout_width="85.5dp"
                android:layout_height="58.5dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@drawable/remote_control_button" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/file_manager_button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="0.50"
            android:background="@drawable/menu_button_xml"
            android:clickable="true"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/imageView_file_manager"
                android:layout_width="85.5dp"
                android:layout_height="58.5dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@drawable/file_manager_button" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/desktop_button"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_weight="0.50"
            android:background="@drawable/menu_button_xml"
            android:clickable="true"
            android:gravity="center_horizontal" >

            <ImageView
                android:id="@+id/imageView_desktop"
                android:layout_width="85.5dp"
                android:layout_height="58.5dp"
                android:background="@null"
                android:contentDescription="@null"
                android:src="@drawable/desktop_mode_button" />
        </LinearLayout>
    </LinearLayout>

    <RelativeLayout
        android:id="@+id/fragment_container"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:layout_alignParentRight="true"
        android:layout_alignParentTop="false"
        android:layout_below="@+id/menuBar"
        android:baselineAligned="true"
        android:orientation="vertical"
        android:visibility="visible" >

    </RelativeLayout>


</RelativeLayout>

これは可視性を処理するコードです

public void connectService(String ip, String hostType, String name) {
    server = new ConnectedServer(ip, hostType, "Presento");
    Toast.makeText(getApplicationContext(), "You have been connected to Presento Server with IP: " + ip, Toast.LENGTH_LONG).show();

    //RelativeLayout.LayoutParams params = (RelativeLayout.LayoutParams) fragmentContainer.getLayoutParams();
    //RelativeLayout.LayoutParams param2 = (RelativeLayout.LayoutParams) belowMenu.getLayoutParams();
    //param2.height = 65;
    //param2.addRule(RelativeLayout.ABOVE, R.id.fragment_container);
    //param2.addRule(RelativeLayout.BELOW, R.id.titleBar);
    belowMenu.setVisibility(View.VISIBLE);
        belowMenu.startAnimation(new MyScaler(1.0f, 1.0f, 0.0f, 1.0f, 500, belowMenu, false));

    //belowMenu.setLayoutParams(param2);
    //params.addRule(RelativeLayout.BELOW,R.id.menuBar);
    //fragmentContainer.setLayoutParams(params);
    //fragmentContainer.setVisibility(View.GONE);
    //fragmentContainer.setVisibility(View.VISIBLE);

}

そして、これはGONEのときに処理するコードです

connectButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                // TODO Auto-generated method stub
                //if not yet connected to a server, find a server through jmdns and get the ip
                if (server == null) {
                    //setting device's ip address
                    myIpAddress = getMyIpAddress();
                    InetAddress inet = intToInetAddress(ipStringToInt(myIpAddress));
                    if (myIpAddress.equals("")) alertMessage("You don't seem to be connected to a Wi-Fi Service, please make sure that you are connected and try to connect again.", "Something went wrong");
                    else {
                        new SeekServer(inet, MenuActivity.this).execute(jmdns);
                    }
                }
                //server already connected
                else {
                    FragmentManager FM = getSupportFragmentManager();
                    FragmentTransaction FT = FM.beginTransaction();
                    String sessionID = pref.getString("sessionID", "0");
                    FT.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
                    try {
                    RemoteControlFragment remote = (RemoteControlFragment)FM.findFragmentById(R.id.fragment_container);
                    if (sessionID.equals("0")) {
                        join = new JoinSessionFragment();
                        FT.replace(R.id.fragment_container, join);
                        FT.commit();
                    } else {
                        String accountName = pref.getString("accountName", "");
                        status.setText(accountName);
                        FT.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
                        TutorialFragment tutor = new TutorialFragment();
                        FT.replace(R.id.fragment_container, tutor);
                        FT.addToBackStack(null);
                        FT.commit();
                    }
                    } catch (ClassCastException ex) {
                        try {
                        FileManagerFragment manager = (FileManagerFragment)FM.findFragmentById(R.id.fragment_container);
                        if (sessionID.equals("0")) {
                            join = new JoinSessionFragment();
                            FT.replace(R.id.fragment_container, join);
                            FT.commit();
                        } else {
                            String accountName = pref.getString("accountName", "");
                            status.setText(accountName);
                            FT.setCustomAnimations(R.anim.slide_in_right, R.anim.slide_out_left);
                            TutorialFragment tutor = new TutorialFragment();
                            FT.replace(R.id.fragment_container, tutor);
                            FT.addToBackStack(null);
                            FT.commit();
                        }
                        }
                        catch (ClassCastException ex2) {

                        }
                    }


                    Toast.makeText(getApplicationContext(), "You have been disconnected from server", Toast.LENGTH_LONG).show();
                    belowMenu.startAnimation(new MyScaler(1.0f, 1.0f, 1.0f, 0.0f, 500, belowMenu, true));

                    server = null;
                        if (jmdns != null) {
                        jmdns.unregisterAllServices();
                        try {
                            jmdns.close();
                        } catch (IOException e) {
                            // TODO Auto-generated catch block
                            e.printStackTrace();
                        }
                    }

                }
            }
        });

アニメーションクラス

public class MyScaler extends ScaleAnimation {

        private View mView;

        private LayoutParams mLayoutParams;

        private int mMarginBottomFromY, mMarginBottomToY;

        private boolean mVanishAfter = false;

        public MyScaler(float fromX, float toX, float fromY, float toY, int duration, View view,
                boolean vanishAfter) {
            super(fromX, toX, fromY, toY);
            setDuration(duration);
            mView = view;
            mVanishAfter = vanishAfter;
            mLayoutParams = (LayoutParams) view.getLayoutParams();
            int height = mView.getHeight();
            mMarginBottomFromY = (int) (height * fromY) + mLayoutParams.bottomMargin - height;
            mMarginBottomToY = (int) (0 - ((height * toY) + mLayoutParams.bottomMargin)) - height;
        }

        @Override
        protected void applyTransformation(float interpolatedTime, Transformation t) {
            super.applyTransformation(interpolatedTime, t);
            if (interpolatedTime < 1.0f) {
                int newMarginBottom = mMarginBottomFromY
                        + (int) ((mMarginBottomToY - mMarginBottomFromY) * interpolatedTime);
                mLayoutParams.setMargins(mLayoutParams.leftMargin, mLayoutParams.topMargin,
                    mLayoutParams.rightMargin, newMarginBottom);
                mView.getParent().requestLayout();
            } else if (mVanishAfter) {
                mView.setVisibility(View.GONE);
            }
        }

    }

最初はアニメーションが原因ではないかと疑っていましたが、ビデオと同じ結論に達したアニメーションなしで GONE と VISIBLE をはっきりと使用しました。

4

0 に答える 0