查看#bringToFront无法处理按钮,仅适用于Android

时间:2016-03-19 10:27:09

标签: android

我的布局的XML就像这样

<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"
tools:context="com.hirewand.hudki.UploadResumeActivity"
android:background="#303030"
android:id="@+id/rootLayout">

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="60dp"
    android:id="@+id/actionBar"
    android:background="@color/black">
    <ImageButton
        android:layout_width="60dp"
        android:layout_height="match_parent"
        android:background="@drawable/ic_menu"
        android:id="@+id/menu_button"
        android:layout_marginLeft="13dp"
        android:onClick="moveMenu"/>
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:text="Your profile"
        android:layout_toRightOf="@id/menu_button"
        android:gravity="center_vertical"
        android:textSize="25dp"
        android:layout_marginLeft="10dp"
        android:textColor="@color/white"/>
</RelativeLayout>
<RelativeLayout
    android:layout_width="80dp"
    android:layout_height="match_parent"
    android:id="@+id/fragmentPlaceholder"
    android:background="@color/black"
    android:layout_below="@id/actionBar">
</RelativeLayout>
<Button
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:layout_marginTop="170dp"
    android:text="UPLOAD RESUME"
    android:id="@+id/uploadButton"
    android:background="@drawable/button_bg_rounded_corners"
    android:layout_centerHorizontal="true"
    android:onClick="startSignupActivity"
    android:drawableLeft="@drawable/ic_action_upload"
    android:drawablePadding="0dp"
    />
<TextView
    android:layout_width="250dp"
    android:layout_height="wrap_content"
    android:text="This helps us find the perfect job for you"
    android:gravity="center_horizontal"
    android:layout_centerHorizontal="true"
    android:textColor="@color/white"
    android:textSize="25dp"
    android:layout_below="@id/uploadButton"
    android:layout_marginTop="70dp"/>
</RelativeLayout>

我正在动态地将一个片段添加到占位符并为其设置动画onClick

这是我的活动的Java:

public class UploadResumeActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_upload_resume);

    //Hide the place holder, View.GONE implies it occupies no space
    RelativeLayout r1 = (RelativeLayout) findViewById(R.id.fragmentPlaceholder);
    android.app.FragmentTransaction ft = getFragmentManager().beginTransaction();
    ft.add(R.id.fragmentPlaceholder, NavigationFragment.newInstance());
    ft.commit();
    r1.bringToFront();
    r1.setVisibility(View.GONE);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    return false;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    //noinspection SimplifiableIfStatement
    return super.onOptionsItemSelected(item);
}

public void moveMenu(View view) {
    RelativeLayout r1 = (RelativeLayout) findViewById(R.id.fragmentPlaceholder);
    Animation slideIn,slideOut;
    slideIn = AnimationUtils.loadAnimation(this,R.anim.enter_from_left);
    slideOut = AnimationUtils.loadAnimation(this,R.anim.exit_to_left);
    if(r1.getVisibility() == View.GONE)
    {
        r1.startAnimation(slideIn);
        r1.setVisibility(View.VISIBLE);

    }
    else
    {
        r1.startAnimation(slideOut);
        r1.setVisibility(View.GONE);
    }

}
}

它的外观如下:Initially

当我尝试通过点击:Upload button need to go behind

打开片段时

我需要上传按钮才能进入片段后面。它在我使用View.setZ()时有效。但我的最低API级别为14.为什么View.bringToFront()不能处理按钮?

1 个答案:

答案 0 :(得分:0)

Steve Cs解决方案包含我的按钮和RelativeLayout内的Textview工作。