Skip to main content

Posts

Showing posts with the label layouts

Divide Layouts into Two Parts Programmatically(without using xml)

For this we just need a class and we will programmatically create the Layouts. And after this we will add Buttons in each layout. package com.AndroidDevelopmentGuru.progmatic; import android.app.Activity; import android.graphics.Color; import android.os.Bundle; import android.view.Gravity; import android.widget.Button; import android.widget.LinearLayout; import android.widget.LinearLayout.LayoutParams; public class progmmatic extends Activity {     @Override     protected void onCreate(Bundle savedInstanceState) {         // TODO Auto-generated method stub         super.onCreate(savedInstanceState);                 //creating a Linear Layout         LinearLayout parent_layout = new LinearLayout(this);        

Multiple Layouts inside a Parent Layout

To show two different layout inside a parent layout we will be working with linear layout. You just need to specify the weight of child layouts. Here goes the code: activity_main.xml <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/rightLayout" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" >

List View And GridView Layout example in Android

Listview Layout MainActivity.java package com.example.layouts; import android.os.Bundle; import android.app.Activity; import android.content.Intent; import android.view.Menu; import android.view.View; import android.widget.AdapterView; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast; import android.widget.AdapterView.OnItemClickListener; public class MainActivity extends Activity {