Reputation: 15
I've develop an application for my project. In that I don't know how to set layout in all screen. If I change another screen that default screen is also changes. Here is my code. So how can I set layout in all screen.
<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="@drawable/custom_bg">
<RelativeLayout
android:id="@+id/relativemail"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp" >
<LinearLayout
android:id="@+id/imageid"
android:layout_width="wrap_content"
android:layout_height="180dp"
android:layout_marginLeft="55dp"
android:layout_marginRight="55dp"
android:layout_marginTop="20dp"
android:background="@drawable/image_bg"
android:gravity="center" >
<ImageView
android:id="@+id/photo"
android:layout_width="140dp"
android:layout_height="140dp"
android:background="@drawable/upload_photo" />
</LinearLayout>
<LinearLayout
android:id="@+id/buttonid"
android:layout_width="match_parent"
android:layout_height="65dp"
android:layout_below="@id/imageid"
android:layout_marginLeft="12dp"
android:layout_marginRight="12dp"
android:layout_marginTop="15dp"
android:background="@drawable/galary_bg"
android:gravity="center"
android:weightSum="2" >
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<Button
android:id="@+id/camera"
android:layout_width="120dp"
android:layout_height="50dp"
android:background="@drawable/cameraxml" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center" >
<Button
android:id="@+id/galary"
android:layout_width="120dp"
android:layout_height="50dp"
android:background="@drawable/galeryxml" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/saveid"
android:layout_width="wrap_content"
android:layout_height="65dp"
android:layout_below="@+id/buttonid"
android:layout_marginLeft="40dp"
android:layout_marginRight="40dp"
android:layout_marginTop="15dp"
android:background="@drawable/save_bg"
android:gravity="center" >
<Button
android:id="@+id/save"
android:layout_width="120dp"
android:layout_height="50dp"
android:background="@drawable/savexml"/>
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="40dp"
android:gravity="center"
android:layout_alignParentBottom="true"
android:layout_below="@+id/saveid"
android:layout_marginBottom="15dp"
android:layout_marginLeft="84dp" >
<ToggleButton
android:id="@+id/toggleButton1"
android:layout_width="150dp"
android:layout_height="40dp"
android:background="@drawable/chapxml" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
Upvotes: 0
Views: 105
Reputation:
Instead of using dp
, sp
, px
and other hard values you have to use match_parent
and wrap_content
. Those are dynamic values that change by screen width, height and dpi.
Upvotes: 1
Reputation: 1253
You could do it using fragments and only change the specific views that you need to change across activities but an easier option would be to re-use layout using .
Create a layout with all those views and use <merge>
tag to enclose them. Then create different layout files(xml) for different activities and use <include>
as described in the link.
Upvotes: 0