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:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context="showgallery.example.com.splashdialog.MainActivity">
<RelativeLayout android:id="@+id/container" android:text="Hello World!" android:layout_width="match_parent" android:layout_height="wrap_content" />
</RelativeLayout>
MainActivity.java
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.MotionEvent;
import android.view.View;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
RelativeLayout fragmentContainer;
GestureDialog gestureDialog = new GestureDialog();
@Override protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
fragmentContainer = (RelativeLayout) findViewById(R.id.container);
getFragmentManager().beginTransaction().add(R.id.container,new GestureDialog())
.commit();
fragmentContainer.setOnTouchListener(new View.OnTouchListener() {
@Override public boolean onTouch(View view, MotionEvent motionEvent) {
try {
FragmentManager fm = getFragmentManager();
Fragment fragment = fm.findFragmentById(R.id.container);
FragmentTransaction ft = fm.beginTransaction();
ft.remove(fragment);
ft.commit();
}catch (NullPointerException npe)
{
}
return false;
}
});
}
}
Now, add fragment
Create Resource file
layout/activity_gesture_dialog.xml
activity_gesture_dialog.xml
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" android:padding="@dimen/activity_horizontal_margin" >
<ImageView android:id="@+id/splashscreen" android:layout_width="wrap_content" android:layout_height="fill_parent" android:src="@drawable/gesture" android:layout_gravity="center" android:layout_margin="16dp" />
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="Hello World, splash"/>
</LinearLayout>
Now, Create Java Resource File
GestureDialog.java
import android.app.Fragment;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
public class GestureDialog extends Fragment {
@Nullable @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.activity_gesture_dialog, container, false);
return view;
}
}
No comments:
Post a Comment