XML : What 's a good way to align layout across activities when one uses weight in linear layout while the rest does not?

I utilized weight in the LinearLayout in the main screen of my app, but didn't do so in the other activity of my app. My goal is to align the circles and the start stop buttons in both activities, what's the best way to accomplish this? Below are my code for both activities' xml files.

Main activity that utilizes weight in LinearLayout:

      <View          android:id="@+id/leftTopOfApp"          android:layout_alignParentTop="true"          android:layout_width="5dp"          android:layout_height="1dp"          android:background="@android:color/transparent" />        <View          android:id="@+id/topOfApp"          android:layout_toRightOf="@id/leftTopOfApp"          android:layout_width="1dp"          android:layout_height="5dp"          android:background="@android:color/transparent" />        <TextView          android:id="@+id/totalTimeView"          android:paddingTop="5dp"          android:paddingLeft="5dp"          android:paddingRight="5dp"          android:paddingBottom="5dp"          android:layout_width="104dp"          android:layout_height="40dp"          android:gravity="right"          android:textAlignment="gravity"          android:layout_below="@id/topOfApp"          android:layout_toRightOf="@+id/leftTopOfApp"          android:textSize="17sp"            android:background="@android:color/white"          android:textColor="@color/started_black"          />        <ImageButton          android:id="@+id/settings"          android:layout_width="60dp"          android:layout_height="50dp"          android:layout_alignParentTop="true"          android:layout_alignParentRight="true"          android:src="@drawable/ic_settings_black_24dp"          android:scaleType="fitXY"          />        <View          android:id="@+id/settingsToLinear"          android:layout_below="@id/settings"          android:layout_width="1dp"          android:layout_height="30dp"          android:background="@android:color/transparent" />        <LinearLayout          android:layout_width="match_parent"          android:layout_height="match_parent"          android:layout_below="@id/settingsToLinear"          android:gravity="center_horizontal"          android:weightSum="3"          android:orientation="vertical"          >        <TextView          android:id="@+id/countDownView"          android:layout_width="wrap_content"          android:layout_height="0dp"          android:layout_weight="1.8"          android:background="@drawable/white_circle"          android:textColor="@color/started_black"          android:gravity="center"          android:textSize="65sp" />        <View          android:layout_width="1dp"          android:layout_height="0dp"          android:layout_weight="0.15"          android:background="@android:color/transparent" />        <ToggleButton          android:id="@+id/toggleSwitch"          android:background="@drawable/toggle_selector"          android:layout_width="250dp"          android:layout_height="0dp"          android:layout_weight="0.3"          android:text=""          android:textOn=""          android:textOff=""          />        <View          android:layout_width="1dp"          android:layout_height="0dp"          android:layout_weight="0.17"          android:background="@android:color/transparent" />        <ImageButton          android:id="@+id/startButton"          android:background="@drawable/button_selector"          android:layout_width="275dp"          android:layout_height="0dp"          android:layout_weight="0.35"          />        </LinearLayout>  </RelativeLayout>    

Started activity that doesn't not utilize weight at all.

  <?xml version="1.0" encoding="utf-8"?>  <!--layout for when timer is started-->  <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:background="@color/green_go"      android:paddingBottom="60dp"      android:paddingLeft="35dp"      android:paddingRight="35dp"      tools:context=".MainActivity">        <Chronometer          android:id="@+id/currentElapsed"          android:layout_centerInParent="true"          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:background="@drawable/white_circle"          android:gravity="center"          android:textColor="@color/green_go"          android:textSize="65sp" />        <ImageButton          android:id="@+id/stopButton"          android:background="@drawable/stop_button"          android:layout_centerHorizontal="true"          android:layout_width="150dp"          android:layout_height="70dp"          android:layout_alignParentBottom="true" />  </RelativeLayout>    

Main ActivityStarted Activity

Any advice is appreciated, thank you!

No comments:

Post a Comment