View#bringToFront不在按钮上工作,仅在Android中的TextView上工作
我的布局的XML是这样的View#bringToFront不在按钮上工作,仅在Android中的TextView上工作,android,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.Uploa
<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>
这就是它的样子:
当我尝试通过单击打开片段时:
我需要上传按钮在片段后面。当我使用
View.setZ()
时,它可以工作。但我的最小API级别是14。为什么不View.bringToFront()呢
在按钮上工作?将我的按钮和文本视图封装在相对论窗口中的Steve Cs解决方案工作。将我的按钮和文本视图封装在相对论窗口中的Steve Cs解决方案工作。为什么不将最后一个按钮和文本视图封装在另一个相对论布局中?它看起来很好。你期待什么?否则,为什么不将按钮布局移动到布局中的片段占位符之前,默认情况下,它将位于后面。感谢Steve,将我的按钮和文本视图封装在relativelayout中。:)@JHH它被带到了文本视图的前面,但不是按钮,我想知道为什么..为什么不把你的最后一个按钮和文本视图放在另一个相对的布局中呢?它似乎被带到了前面。你期待什么?否则,为什么不将按钮布局移动到布局中的片段占位符之前,默认情况下,它将位于后面。感谢Steve,将我的按钮和文本视图封装在relativelayout中。:)@JHH它被带到文本视图的前面,但不是按钮,我想知道为什么。。
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);
}
}
}