【发布时间】:2016-12-20 12:30:28
【问题描述】:
好的,我要实现的是来自 ET-Money android 应用程序的以下行为: 单击 2016 年 12 月微调器时,有一个视图会在屏幕上向下滑动,并使背景视图/布局可见性变暗。
到目前为止,我所做的是创建了一个片段(具有透明的深色背景),它与当前活动布局重叠并在单击时添加了幻灯片过渡。
但这不是我需要的确切行为,因为这样片段的整个黑暗透明布局在当前活动上滑动,而我需要的是背景布局淡入黑色而不是与片段布局一起滑入。 (和原来的应用一样,只有白色背景的日期选择视图在activity中滑动,背景同时淡出)
我怎样才能实现所需的行为?
主要活动:
public class MainActivity extends AppCompatActivity {
public Button clickme;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final android.app.Fragment fragment = this.getFragmentManager().findFragmentById(R.id.menuFragment);
this.getFragmentManager().beginTransaction().hide(fragment).commit();
clickme = (Button) findViewById(R.id.clickme);
clickme.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "clicked", Toast.LENGTH_SHORT).show();
FragmentManager fragmentManager = getFragmentManager();
android.app.FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
fragmentTransaction.setCustomAnimations(R.animator.slide_up, 0);
fragmentTransaction.show(fragment).commit();
}
});
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.svatts.testapp.MainActivity">
<FrameLayout
android:id="@+id/scene_root"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/back"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="@+id/clickme"
android:layout_width="40dp"
android:layout_height="50dp"
android:text="click me" />
</FrameLayout>
<fragment
android:id="@+id/menuFragment"
android:name="com.example.svatts.testapp.MyFrag"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center_horizontal" />
</FrameLayout>
</RelativeLayout>
MyFrag.java:
public class MyFrag extends Fragment {
Button button ;
@Nullable
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.firstfrag,container,false);
button = (Button)view.findViewById(R.id.butt);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// strart other fragment
Toast.makeText(getActivity(),"clicked here",Toast.LENGTH_SHORT).show();
}
});
return view;
}
}
firstfrag.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#aa000000">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:text="THIS IS TEST BRP" />
<TextView
android:id="@+id/uo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="150dp"
android:text="THIS IS UUOO" />
<Button
android:id="@+id/butt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/uo"
android:text="Click Me" />
</RelativeLayout>
【问题讨论】:
-
我认为你应该使用 DialogFragment 而不是 Fragment
-
哇,好像是这样,我试试看
标签: android android-fragments animation android-animation android-transitions