activity_main.xml
package com.zyasin.linearlayout; import android.os.Bundle; import android.app.Activity; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
<LinearLayout 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:orientation="vertical" tools:context=".LinearLayout"> <Button android:text="BUTTON One" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text One" android:paddingTop="10px"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text Two" android:paddingTop="10px"/>
activity_main.xml
package com.zyasin.linearlayout; import android.os.Bundle; import android.app.Activity; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
<LinearLayout 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:orientation="horizontal" tools:context=".LinearLayout"> <Button android:text="BUTTON One" android:layout_width="wrap_content" android:layout_height="wrap_content" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text One" android:paddingTop="10px"/> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Text Two" android:paddingTop="10px"/> </LinearLayout >
activity_main.xml
package com.zyasin.linearlayout; import android.os.Bundle; import android.app.Activity; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); } }
<Button android:layout_width="100dp" android:layout_height="wrap_content" android:text="Button 1" android:background="#da4453" android:layout_margin="2dp" android:layout_gravity="left" android:layout_weight="3"/> <Button android:layout_width="100dp" android:layout_height="wrap_content" android:text="Button 2" android:background="#da4453" android:layout_margin="2dp" android:layout_gravity="center" android:layout_weight="2"/> <Button android:layout_width="100dp" android:layout_height="wrap_content" android:text="Button 3" android:background="#da4453" android:layout_margin="2dp" android:layout_gravity="right" android:layout_weight="1"/>