Showing posts with label layout. Show all posts

You should you find yourself needing the same view over and over,
this is the best solution for you reuse your layout.

use the include tag just link the include in php. see below





<include android:id="@+id/myid1" layout="@layout/workspace_screen" />


layout/workspace_screen.xml this will be the view that will be include on your
desired view. hope this helps you.















fdf

How to Adding a layout in another layout (reuse)

One of the most coolest things you can add on your activity, is the ability to create a custom popup activity. Follow the steps bellow.

1. We are going to create a layout for our popup activity res/layout/popup_activity.xml the file name does not matter.



<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"    xmlns:tools="http://schemas.android.com/tools"    tools:context="com.designspaza.carcontroller.PopupActivity"    android:layout_width="match_parent"    android:layout_height="match_parent"    android:background="#555"    android:gravity="center"    android:orientation="vertical"    android:id="@+id/pop_layout">

    <TextView        android:id="@+id/pop_title"        android:layout_width="wrap_content"        android:layout_height="50dp"        android:background="@android:color/transparent"        android:gravity="center_horizontal"        android:text="POP1"        android:textColor="#fff"        android:textSize="20sp" />

    <Button        android:id="@+id/close_btn"        android:layout_width="100dp"        android:layout_height="60dp"        android:text="Close" />
</LinearLayout>


2. next create the PopupActivity class to handle any View present on your popup

public class PopupActivity extends Activity {
@Override    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.popup_activity);

Note: popup_activity: is the name of our popup layout.

3. we need a theme for our popup, see below.

<style name="AppTheme.PopMe" parent="Theme.AppCompat.Light.DarkActionBar">
    <item name="android:windowIsTranslucent">true</item>
    <item name="android:windowCloseOnTouchOutside">true</item>
</style>

android:windowIsTranslucent: will make the pop up transparent beyond its borders.
android:windowCloseOnTouchOutside: will close the pop up when you click out side its borders.

4. we need to register our class with the manifest file manifests/AndroidManifest.xml

<activity    android:name=".PopupActivity"    android:theme="@style/AppTheme.PopMe" />


5. here i will show you how to actually display the popup after a click event.

    //details direction for popup    button.setOnClickListener(new View.OnClickListener(){
        @Override        public void onClick(View v) {
            Intent i = new Intent(context.getApplicationContext(), PopupActivity.class);
            context.startActivity(i);
        }
    });

Note: PopupActivity: is the name of our class.


I hope this was very helpful. Also read how to pass values to your popup activity.












How To create a pop up Activity on your current Activity

►

- Copyright © Mdunge Apps - Blogger Templates - Powered by Blogger - Designed by Johanes Djogan -