I'm not sure exactly why this is happening but I've created a GridLayout in Android and it does not fill_parent evenly as expected. Most of the icons are smushed to the left - and are not evenly distributed.
Can anyone spot why this might be happening?
Screenshot:
XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/download"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black"
android:weightSum="1" >
<RelativeLayout
android:id="#+id/rl_ListView2"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:background="#color/black" >
<RelativeLayout
android:id="#+id/rl_ListView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:gravity="left"
android:paddingBottom="65dp" />
<ImageView
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:gravity="right"
android:paddingBottom="65dp"
android:scaleType="fitXY" />
</RelativeLayout>
<ImageView
android:id="#+id/boxart"
android:layout_width="450dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:adjustViewBounds="true"
android:gravity="left"
android:paddingBottom="65dp" />
<RelativeLayout
android:id="#+id/rl_ListView2a"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="450dp"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:layout_alignParentTop="true" >
<GridLayout
android:id="#+id/GridLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:columnCount="5"
android:columnWidth="300dip"
android:gravity="center"
android:horizontalSpacing="100dip"
android:numColumns="auto_fit"
android:orientation="vertical"
android:rowCount="6"
android:stretchMode="spacingWidthUniform"
android:verticalSpacing="100dip" >
<Switch
android:id="#+id/switch1"
android:layout_column="0"
android:layout_gravity="left|bottom"
android:layout_row="3" />
<Switch
android:id="#+id/switch2"
android:layout_column="1"
android:layout_gravity="left|bottom"
android:layout_row="3" />
<Switch
android:id="#+id/switch3"
android:layout_column="3"
android:layout_gravity="left|bottom"
android:layout_row="3" />
<ImageView
android:id="#+id/imageView7"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_column="1"
android:layout_gravity="center_horizontal|top"
android:layout_row="5"
android:src="#drawable/icon_shopping" />
<ImageView
android:id="#+id/imageView8"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_column="3"
android:layout_gravity="center_horizontal|top"
android:layout_row="5"
android:src="#drawable/icon_superfan" />
<Switch
android:id="#+id/switch4"
android:layout_column="4"
android:layout_gravity="left|bottom"
android:layout_row="3" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_column="4"
android:layout_gravity="center_horizontal|top"
android:layout_row="3"
android:src="#drawable/icon_quotes" />
<ImageView
android:id="#+id/imageView4"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_column="3"
android:layout_gravity="center_horizontal|top"
android:layout_row="3"
android:src="#drawable/icon_plotinfo" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_column="1"
android:layout_gravity="center_horizontal|top"
android:layout_row="3"
android:src="#drawable/icon_locations" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_column="0"
android:layout_gravity="center_horizontal|top"
android:layout_row="3"
android:src="#drawable/icon_dilemmas" />
<ImageView
android:id="#+id/imageView12"
android:layout_margin="20dp"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_column="3"
android:layout_gravity="center_horizontal|top"
android:layout_row="1"
android:src="#drawable/icon_vehicles_top_center" />
<ImageView
android:id="#+id/imageView13"
android:layout_margin="20dp"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_column="4"
android:layout_gravity="center_horizontal|top"
android:layout_row="1"
android:src="#drawable/icon_weapons_top_center" />
<ImageView
android:id="#+id/imageView6"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_column="0"
android:layout_gravity="center_horizontal|top"
android:layout_row="5"
android:src="#drawable/icon_recipe" />
<ImageView
android:id="#+id/imageView9"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_column="4"
android:layout_gravity="center_horizontal|top"
android:layout_row="5"
android:src="#drawable/icon_trivia" />
<Switch
android:id="#+id/switch8"
android:layout_column="4"
android:layout_gravity="left|bottom"
android:layout_row="5" />
<Switch
android:id="#+id/switch7"
android:layout_column="3"
android:layout_gravity="left|bottom"
android:layout_row="5" />
<Switch
android:id="#+id/switch6"
android:layout_column="1"
android:layout_gravity="left|bottom"
android:layout_row="5" />
<Switch
android:id="#+id/switch5"
android:layout_column="0"
android:layout_gravity="left|bottom"
android:layout_row="5" />
<ImageView
android:id="#+id/imageView10"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_margin="20dp"
android:layout_column="0"
android:layout_gravity="center|bottom"
android:layout_row="1"
android:src="#drawable/icon_music_top_center" />
<ImageView
android:id="#+id/imageView11"
android:layout_margin="20dp"
android:layout_width="50dp"
android:layout_height="100dp"
android:layout_column="1"
android:layout_gravity="center_horizontal|top"
android:layout_row="1"
android:src="#drawable/icon_who_top_center" />
</GridLayout>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="On Demand"
android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>
<LinearLayout
android:id="#+id/footer"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:layout_alignParentBottom="true"
android:background="#drawable/timeline_bottom_android"
android:orientation="horizontal" >
<ImageView
android:id="#+id/backbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:gravity="left"
android:src="#drawable/icon_back_arrow" />
<TextView
android:id="#+id/backButtonTxt"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignRight="#+id/saveButton"
android:gravity="center_vertical"
android:text="Movies"
android:textSize="40sp" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
android:layout_gravity="center_horizontal|top" should be android:layout_gravity="left|bottom" for imageView9 (etc)
Related
In Android Studio I have a ScrollView and inside a layout with TextView, ImageView, another few objects and then a button.
In my app everytime you click on the button, the TextView adds another line (up to a limit), how can I prevent the button changing its place in the layout when adding a new line? (All of the objects except for one TextView and the button are Invisble).
Preview:
XML:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".GameActivity">
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="#+id/levelTV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Level 1"
android:textSize="14sp" />
<TextView
android:id="#+id/senTV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:text="Sentence"
android:textSize="24sp"
android:textStyle="bold" />
<TextView
android:id="#+id/transTV"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Translation"
android:textAlignment="textStart"
android:textSize="24sp" />
<ImageView
android:id="#+id/pic"
android:layout_width="match_parent"
android:layout_height="130dp"
app:srcCompat="#android:drawable/btn_dialog" />
<EditText
android:id="#+id/picET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="word in the pic"
android:minHeight="48dp" />
<ImageButton
android:id="#+id/backBtn"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_gravity="right"
app:srcCompat="#android:drawable/ic_input_delete"
tools:ignore="SpeakableTextPresentCheck"
android:onClick="back"/>
<com.google.android.material.chip.ChipGroup
android:id="#+id/bank"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
>
<com.google.android.material.chip.Chip
android:id="#+id/word1"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:tag="0"
android:text="word1"
android:textAlignment="center"
android:theme="#style/Theme.MaterialComponents.Light" />
<com.google.android.material.chip.Chip
android:id="#+id/word2"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:tag="1"
android:text="word2"
android:textAlignment="center"
android:theme="#style/Theme.MaterialComponents.Light" />
<com.google.android.material.chip.Chip
android:id="#+id/word3"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:tag="2"
android:textAlignment="center"
android:theme="#style/Theme.MaterialComponents.Light"
tools:text="word3" />
<com.google.android.material.chip.Chip
android:id="#+id/word4"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:tag="3"
android:text="word4"
android:textAlignment="center"
android:theme="#style/Theme.MaterialComponents.Light" />
<com.google.android.material.chip.Chip
android:id="#+id/word5"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="4"
android:textAlignment="center"
android:theme="#style/Theme.MaterialComponents.Light"
tools:text="word5" />
<com.google.android.material.chip.Chip
android:id="#+id/word6"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="5"
android:textAlignment="center"
android:theme="#style/Theme.MaterialComponents.Light"
tools:text="word6" />
<com.google.android.material.chip.Chip
android:id="#+id/word7"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="6"
android:text="word7"
android:textAlignment="center"
android:theme="#style/Theme.MaterialComponents.Light" />
<com.google.android.material.chip.Chip
android:id="#+id/word8"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="7"
android:text="word8"
android:textAlignment="center"
android:theme="#style/Theme.MaterialComponents.Light" />
<com.google.android.material.chip.Chip
android:id="#+id/word9"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="8"
android:text="word9"
android:textAlignment="center" />
<com.google.android.material.chip.Chip
android:id="#+id/word10"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="9"
android:text="word10"
android:textAlignment="center" />
<com.google.android.material.chip.Chip
android:id="#+id/word11"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="10"
android:textAlignment="center"
tools:text="word11" />
<com.google.android.material.chip.Chip
android:id="#+id/word12"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:tag="11"
android:text="word12"
android:textAlignment="center" />
</com.google.android.material.chip.ChipGroup>
<Button
android:id="#+id/checkBtn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:backgroundTint="#80DEEA"
android:onClick="check"
android:text="הבא"
android:textSize="16sp"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</LinearLayout
I'm using Android Studio since some weeks. After my first experience I'm building my first APK und have a problem with the Relative layout.
After I'm putting the stuff (ImageBtn, TextView) into it and trying to run the app in the emulator, it shows only the left side.
enter image description here
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/beer" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton5"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_toEndOf="#+id/imageButton5"
android:layout_toRightOf="#+id/imageButton5"
android:text="Beer"
android:textSize="18sp" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton5"
android:layout_alignLeft="#+id/textView11"
android:layout_alignStart="#+id/textView11" />
<ImageButton
android:id="#+id/imageButton6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="110dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/frenchfries" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView11"
android:layout_alignStart="#+id/textView11"
android:layout_alignTop="#+id/imageButton6"
android:text="French Frits"
android:textSize="18sp" />
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Level 0"
android:textSize="18sp"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/textView13"
android:layout_alignStart="#+id/textView13" />
<ImageButton
android:id="#+id/imageButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="190dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/icecream" />
<TextView
android:id="#+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView14"
android:layout_alignStart="#+id/textView14"
android:layout_alignTop="#+id/imageButton7"
android:text="Ice Cream"
android:textSize="18sp" />
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView15"
android:layout_alignStart="#+id/textView15"
android:layout_below="#+id/textView15"
android:text="Level 0"
android:textSize="18sp" />
<ImageButton
android:id="#+id/imageButton9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/background_light"
app:srcCompat="#drawable/pizza"
android:layout_alignTop="#+id/textView11"
android:layout_toRightOf="#+id/textView13"
android:layout_toEndOf="#+id/textView13"
android:layout_marginLeft="28dp"
android:layout_marginStart="28dp" />
<TextView
android:id="#+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView12"
android:layout_marginLeft="14dp"
android:layout_marginStart="14dp"
android:layout_toEndOf="#+id/imageButton9"
android:layout_toRightOf="#+id/imageButton9"
android:text="Pizza"
android:textSize="18sp" />
<TextView
android:id="#+id/textView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Level 0"
android:textSize="18sp"
android:layout_below="#+id/textView11"
android:layout_alignLeft="#+id/textView17"
android:layout_alignStart="#+id/textView17" />
<TextView
android:id="#+id/textView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/textView15"
android:layout_marginLeft="102dp"
android:layout_marginStart="102dp"
android:layout_toEndOf="#+id/textView18"
android:layout_toRightOf="#+id/textView18"
android:text="TextView" />
</RelativeLayout>
Hope you can help me to fix that problem.
Greetings Phil Newman
I will present two ways I would do this if it was me. So you can also choose from this to suit your need.
METHOD ONE
You can use a LinearLayout with vertical orientation as the parent layout.
Use another LinearLayout with horizontal orientation to host a two RelativeLayouts. Each RelativeLayout will also contain the three components(ImageButton, TextViews).
Looks at an xml text I have presented here:
<LinearLayout
android:id="#+id/lay1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".50">
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/beer" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton5"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_toEndOf="#+id/imageButton5"
android:layout_toRightOf="#+id/imageButton5"
android:text="Beer"
android:textSize="18sp" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton5"
android:layout_alignLeft="#+id/textView11"
android:layout_alignStart="#+id/textView11" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".50">
<ImageButton
android:id="#+id/imageButton6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/frenchfries" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton6"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_toEndOf="#+id/imageButton6"
android:layout_toRightOf="#+id/imageButton6"
android:text="French Frits"
android:textSize="18sp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton6"
android:layout_alignLeft="#+id/textView1"
android:layout_alignStart="#+id/textView1" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/lay2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".50">
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/icecream" />
<TextView
android:id="#+id/textView0"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton2"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_toEndOf="#+id/imageButton2"
android:layout_toRightOf="#+id/imageButton2"
android:text="Ice Cream"
android:textSize="18sp" />
<TextView
android:id="#+id/textView102"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton2"
android:layout_alignLeft="#+id/textView0"
android:layout_alignStart="#+id/textView0" />
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".50">
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/pizza" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton3"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_toEndOf="#+id/imageButton3"
android:layout_toRightOf="#+id/imageButton3"
android:text="Pizza"
android:textSize="18sp" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton3"
android:layout_alignLeft="#+id/textView3"
android:layout_alignStart="#+id/textView3" />
</RelativeLayout>
</LinearLayout>
You can analyse it carefully and just copy and paste depending on the number of buttons(your categories) you want.
METHOD TWO
Arrange everything well in the Relative layout (linearly or preferably a LinearLayout) and put the RelativeLayout in a ScrollView layout as the parent layout. This will enable the user to scroll down and up if the widgets are out of view.
Also here is an xml for that:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:id="#+id/imageButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="30dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/beer" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton5"
android:layout_marginLeft="12dp"
android:layout_marginStart="12dp"
android:layout_toEndOf="#+id/imageButton5"
android:layout_toRightOf="#+id/imageButton5"
android:text="Beer"
android:textSize="18sp" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton5"
android:layout_alignLeft="#+id/textView11"
android:layout_alignStart="#+id/textView11" />
<ImageButton
android:id="#+id/imageButton6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="110dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/frenchfries" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView11"
android:layout_alignStart="#+id/textView11"
android:layout_alignTop="#+id/imageButton6"
android:text="French Frits"
android:textSize="18sp" />
<!-- android:layout_marginBottom="7dp" -->
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="7dp"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignBottom="#+id/imageButton6"
android:layout_alignLeft="#+id/textView13"
android:layout_alignStart="#+id/textView13"/>
<ImageButton
android:id="#+id/imageButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="190dp"
android:background="#android:color/background_light"
app:srcCompat="#drawable/icecream" />
<TextView
android:id="#+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView14"
android:layout_alignStart="#+id/textView14"
android:layout_alignTop="#+id/imageButton7"
android:text="Ice Cream"
android:textSize="18sp" />
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView15"
android:layout_alignStart="#+id/textView15"
android:layout_below="#+id/textView15"
android:text="Level 0"
android:textSize="18sp" />
<ImageButton
android:id="#+id/imageButton9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/background_light"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="270dp"
app:srcCompat="#drawable/pizza" />
<TextView
android:id="#+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView16"
android:layout_alignStart="#+id/textView16"
android:layout_alignTop="#+id/imageButton9"
android:text="Pizza"
android:textSize="18sp" />
<TextView
android:id="#+id/textView18"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Level 0"
android:textSize="18sp"
android:layout_alignLeft="#+id/textView17"
android:layout_alignStart="#+id/textView17"
android:layout_below="#+id/textView17" />
</RelativeLayout>
Here is what it looks like currently:
http://i.stack.imgur.com/eaBpP.png
I want buttons to go and align at bottom (and cover all screen from sides too). I try to do this but getting unexpected results. Here is layout code:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000" >
<GridLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="3" >
<TextView
android:id="#+id/result"
android:layout_width="238dp"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_marginRight="40dp"
android:layout_row="0"
android:gravity="right"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFF00"
android:textSize="35sp"
android:textStyle="bold" />
<Space
android:layout_width="271dp"
android:layout_height="1dp"
android:layout_column="0"
android:layout_row="0" />
<ImageButton
android:id="#+id/clear"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_gravity="left"
android:layout_row="1"
android:layout_rowSpan="2"
android:paddingLeft="4dp"
android:src="#android:drawable/ic_input_delete" />
<Space
android:layout_width="12dp"
android:layout_height="15dp"
android:layout_column="2"
android:layout_row="1" />
<Space
android:layout_width="100dp"
android:layout_height="14dp"
android:layout_column="0"
android:layout_row="2" />
<Space
android:layout_width="100dp"
android:layout_height="13dp"
android:layout_row="2" />
</GridLayout>
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:gravity="center" >
<Button
android:id="#+id/seven"
android:layout_width="80dp"
android:layout_height="100dp"
android:text="7"
android:textSize="50sp" />
<Button
android:id="#+id/eight"
android:layout_width="80dp"
android:layout_height="100dp"
android:text="8"
android:textSize="50sp" />
<Button
android:id="#+id/nine"
android:layout_width="80dp"
android:layout_height="100dp"
android:text="9"
android:textSize="50sp" />
<Button
android:id="#+id/divide"
style="#dimen/activity_horizontal_margin"
android:layout_width="80dp"
android:layout_height="100dp"
android:text="/"
android:textSize="50sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:id="#+id/four"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="4"
android:textSize="50sp" />
<Button
android:id="#+id/five"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="5"
android:textSize="50sp" />
<Button
android:id="#+id/six"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="6"
android:textSize="50sp" />
<Button
android:id="#+id/multiply"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="x"
android:textSize="50sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="1"
android:textSize="50sp" />
<Button
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="2"
android:textSize="50sp" />
<Button
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="3"
android:textSize="50sp" />
<Button
android:id="#+id/minus"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="-"
android:textSize="50sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="#+id/dot"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="."
android:textSize="50sp" />
<Button
android:id="#+id/zero"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="0"
android:textSize="50sp" />
<Button
android:id="#+id/equals"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="="
android:textSize="50sp" />
<Button
android:id="#+id/plus"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:text="+"
android:textSize="50sp" />
</TableRow>
</TableLayout>
Try this code to make the Numbers Grid covering the side spaces and the bottom space.Checkout if it is required o/p.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#000000" >
<GridLayout
android:id="#+id/grid"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="3" >
<TextView
android:id="#+id/result"
android:layout_width="238dp"
android:layout_height="wrap_content"
android:layout_column="0"
android:layout_gravity="left"
android:layout_marginRight="40dp"
android:layout_row="0"
android:gravity="right"
android:text=""
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#FFFF00"
android:textSize="35sp"
android:textStyle="bold" />
<Space
android:layout_width="271dp"
android:layout_height="1dp"
android:layout_column="0"
android:layout_row="0" />
<ImageButton
android:id="#+id/clear"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_gravity="left"
android:layout_row="1"
android:layout_rowSpan="2"
android:paddingLeft="4dp"
android:src="#android:drawable/ic_input_delete" />
<Space
android:layout_width="12dp"
android:layout_height="15dp"
android:layout_column="2"
android:layout_row="1" />
<Space
android:layout_width="100dp"
android:layout_height="14dp"
android:layout_column="0"
android:layout_row="2" />
<Space
android:layout_width="100dp"
android:layout_height="13dp"
android:layout_row="2" />
</GridLayout>
<TableLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_below="#id/grid"
android:gravity="bottom" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="30dp"
android:gravity="center" >
<Button
android:id="#+id/seven"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="7"
android:textSize="50sp" />
<Button
android:id="#+id/eight"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="8"
android:textSize="50sp" />
<Button
android:id="#+id/nine"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="9"
android:textSize="50sp" />
<Button
android:id="#+id/divide"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="/"
android:textSize="50sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:id="#+id/four"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="4"
android:textSize="50sp" />
<Button
android:id="#+id/five"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="5"
android:textSize="50sp" />
<Button
android:id="#+id/six"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="6"
android:textSize="50sp" />
<Button
android:id="#+id/multiply"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="x"
android:textSize="50sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center" >
<Button
android:id="#+id/one"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="1"
android:textSize="50sp" />
<Button
android:id="#+id/two"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="2"
android:textSize="50sp" />
<Button
android:id="#+id/three"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="3"
android:textSize="50sp" />
<Button
android:id="#+id/minus"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="-"
android:textSize="50sp" />
</TableRow>
<TableRow
android:id="#+id/tableRow14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" >
<Button
android:id="#+id/dot"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="."
android:textSize="50sp" />
<Button
android:id="#+id/zero"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="0"
android:textSize="50sp" />
<Button
android:id="#+id/equals"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="="
android:textSize="50sp" />
<Button
android:id="#+id/plus"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:text="+"
android:textSize="50sp" />
</TableRow>
</TableLayout>
I add some sample code. Try to use this. It is just sample code....
<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:background="#fff"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context=".Home" >
<EditText
android:id="#+id/display"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="20dp" >
<Button
android:id="#+id/seven"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="7"
/>
<Button
android:id="#+id/eight"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="8" />
<Button
android:id="#+id/nine"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="9" />
<Button
android:id="#+id/div"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="/" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="20dp"
android:layout_height="0dp" >
<Button
android:id="#+id/four"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="4" />
<Button
android:id="#+id/five"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="5" />
<Button
android:id="#+id/six"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="6" />
<Button
android:id="#+id/mul"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="*" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="20dp"
android:layout_height="0dp">
<Button
android:id="#+id/one"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="1" />
<Button
android:id="#+id/two"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="2" />
<Button
android:id="#+id/three"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="3" />
<Button
android:id="#+id/sub"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="-" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_weight="1"
android:layout_gravity="center"
android:gravity="center"
android:orientation="horizontal"
android:paddingTop="20dp"
android:layout_height="0dp">
<Button
android:id="#+id/cancel"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="c" />
<Button
android:id="#+id/zero"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="0" />
<Button
android:id="#+id/equal"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="=" />
<Button
android:id="#+id/add"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"
android:text="+" />
</LinearLayout>
</LinearLayout>
This is the first time I'm making an activity xml in landscape model. Until now, what I saw on my computer screen that was what I got on my phone. Now, it's not even close! I placed some layouts, buttons and stuff, centered them like I need them, and tried on the phone and some stuff are way off the screen, some stuff are moved to the right, nothing is like I made it in my xml. So I have to move some stuff a little, then try it on my phone, without any order or rule. Why is this happening?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/backgroundland" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="4" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<Button
android:id="#+id/bA1"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="A1" />
<Button
android:id="#+id/bA2"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="A2" />
<Button
android:id="#+id/bA3"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="A3" />
<Button
android:id="#+id/bA4"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="A4" />
<Button
android:id="#+id/bKolonaA"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="19sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="Kolona A" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="1" >
<Button
android:id="#+id/bB1"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="B1" />
<Button
android:id="#+id/bB2"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="B2" />
<Button
android:id="#+id/bB3"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="B3" />
<Button
android:id="#+id/bB4"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="B4" />
<Button
android:id="#+id/bKolonaB"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="19sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="Kolona B" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<Button
android:id="#+id/bC1"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="C1" />
<Button
android:id="#+id/bC2"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="C2" />
<Button
android:id="#+id/bC3"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="C3" />
<Button
android:id="#+id/bC4"
android:layout_width="115dp"
android:layout_height="35dp"
android:layout_margin="3dp"
android:background="#drawable/buttons"
android:padding="0dp"
android:text="C4"
android:textColor="#ffffff"
android:textSize="18sp" />
<Button
android:id="#+id/bKolonaC"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="19sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="Kolona C" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_weight="1" >
<Button
android:id="#+id/bD1"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="D1" />
<Button
android:id="#+id/bD2"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="D2" />
<Button
android:id="#+id/bD3"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="D3" />
<Button
android:id="#+id/bD4"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="18sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="D4" />
<Button
android:id="#+id/bKolonaD"
android:layout_width="115dp"
android:background="#drawable/buttons"
android:textSize="19sp"
android:textColor="#ffffff"
android:padding="0dp"
android:layout_margin="3dp"
android:layout_height="35dp"
android:text="Kolona D" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="120dp"
android:layout_height="wrap_content" >
<Button
android:id="#+id/bIzlazA"
android:layout_width="50dp"
android:layout_height="35dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="3dp"
android:background="#drawable/buttons_final"
android:padding="0dp"
android:text=""
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="280dp"
android:layout_height="wrap_content" >
<Button
android:id="#+id/bKonacno"
android:layout_width="260dp"
android:layout_height="35dp"
android:layout_marginTop="3dp"
android:background="#drawable/buttons_final"
android:padding="0dp"
android:text=""
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tvVreme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="8dp"
android:text="100"
android:textColor="#ff0000"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
what i know is that the emulator doesn't work same as real devices so why don't you us your phone in debug mode to see what your code really do.
post your code may be we can see if it's not the emulator problem
EDIT:
just add android:layoutweight="1" to the 3 lyouts at the bottom
you should have better results :)
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="120dp"
android:layout_weight="1"
android:layout_height="wrap_content" >
<Button
android:id="#+id/bIzlazA"
android:layout_width="50dp"
android:layout_height="35dp"
android:layout_marginLeft="20dp"
android:layout_marginTop="3dp"
android:background="#drawable/ic_launcher"
android:padding="0dp"
android:text=""
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="280dp"
android:layout_weight="1"
android:layout_height="wrap_content" >
<Button
android:id="#+id/bKonacno"
android:layout_width="260dp"
android:layout_height="35dp"
android:layout_marginTop="3dp"
android:background="#drawable/ic_launcher"
android:padding="0dp"
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="100dp"
android:layout_weight="1"
android:layout_height="match_parent" >
<TextView
android:id="#+id/tvVreme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="8dp"
android:text="100"
android:textColor="#ff0000"
android:textSize="20sp" />
</LinearLayout>
</LinearLayout>
Probably different resolutions on emulator and on device, and you didn't used dpi but pixels.
Also it can be a problem when using absolute layout.
Hard to gues without the code
I have an advmob banner which was added programatically as bellow :
public class MenuActivity extends Activity {
AdView adView ;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activitymain);
adView = new AdView(this, AdSize.BANNER, "a15013b6f790555");
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice(AdRequest.TEST_EMULATOR);
RelativeLayout.LayoutParams relativeParams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.WRAP_CONTENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
relativeParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
adView.loadAd(adRequest);
this.addContentView(adView, relativeParams);
When I run it the banner comes at the top of the screen , I want it to be at the bottom
Here is the xml layout also:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="#drawable/mainbackgroundipad">
<TableRow android:id="#+id/tableRow1">
<ImageButton
android:id="#+id/menu1"
android:layout_width="75dip"
android:layout_height="74dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="57dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu1" />
<ImageButton
android:id="#+id/menu2"
android:layout_width="75dp"
android:layout_height="59dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu2" />
<ImageButton
android:id="#+id/menu3"
android:layout_width="75dip"
android:layout_height="63dip"
android:layout_marginLeft="1dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu3" />
<ImageButton
android:id="#+id/menu4"
android:layout_width="60dp"
android:layout_height="83dp"
android:layout_marginRight="100dp"
android:layout_marginTop="50dp"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
android:src="#drawable/menu4" />
</TableRow>
<TableRow android:id="#+id/tableRow2">
<ImageButton
android:id="#+id/menu5"
android:layout_width="50dp"
android:layout_height="75dp"
android:layout_marginLeft="12dp"
android:layout_marginTop="60dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu5" />
<ImageButton
android:id="#+id/menu6"
android:layout_width="60dp"
android:layout_height="79dp"
android:layout_marginTop="60dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu6" />
<ImageButton
android:id="#+id/menu7"
android:layout_width="60dip"
android:layout_height="86dip"
android:layout_marginLeft="5dp"
android:layout_marginTop="60dp"
android:background="#android:color/transparent"
android:scaleType="fitStart"
android:src="#drawable/menu7" />
<ImageButton
android:id="#+id/menu8"
android:layout_width="75dip"
android:layout_height="50dip"
android:layout_centerVertical="true"
android:layout_marginRight="110dp"
android:layout_marginTop="80dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu8" />
</TableRow>
<TableRow android:id="#+id/tableRow3">
<ImageButton
android:id="#+id/menu9"
android:layout_width="60px"
android:layout_height="80px"
android:layout_marginLeft="2dp"
android:layout_marginTop="40dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu9" />
<ImageButton
android:id="#+id/menu10"
android:layout_width="75dip"
android:layout_height="56dip"
android:layout_alignParentLeft="true"
android:layout_marginLeft="2dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu10" />
<ImageButton
android:id="#+id/menu11"
android:layout_width="75dip"
android:layout_height="65dip"
android:layout_alignParentLeft="true"
android:layout_marginLeft="2dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu11" />
<ImageButton
android:id="#+id/menu12"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="100dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu12" />
</TableRow>
</TableLayout>
Change your XML file like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/rootview"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/mainbackgroundipad"
android:orientation="vertical" >
<TableRow android:id="#+id/tableRow1" >
<ImageButton
android:id="#+id/menu1"
android:layout_width="75dip"
android:layout_height="74dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="57dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu1" />
<ImageButton
android:id="#+id/menu2"
android:layout_width="75dp"
android:layout_height="59dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu2" />
<ImageButton
android:id="#+id/menu3"
android:layout_width="75dip"
android:layout_height="63dip"
android:layout_marginLeft="1dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu3" />
<ImageButton
android:id="#+id/menu4"
android:layout_width="60dp"
android:layout_height="83dp"
android:layout_marginRight="100dp"
android:layout_marginTop="50dp"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
android:src="#drawable/menu4" />
</TableRow>
<TableRow android:id="#+id/tableRow2" >
<ImageButton
android:id="#+id/menu5"
android:layout_width="50dp"
android:layout_height="75dp"
android:layout_marginLeft="12dp"
android:layout_marginTop="60dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu5" />
<ImageButton
android:id="#+id/menu6"
android:layout_width="60dp"
android:layout_height="79dp"
android:layout_marginTop="60dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu6" />
<ImageButton
android:id="#+id/menu7"
android:layout_width="60dip"
android:layout_height="86dip"
android:layout_marginLeft="5dp"
android:layout_marginTop="60dp"
android:background="#android:color/transparent"
android:scaleType="fitStart"
android:src="#drawable/menu7" />
<ImageButton
android:id="#+id/menu8"
android:layout_width="75dip"
android:layout_height="50dip"
android:layout_centerVertical="true"
android:layout_marginRight="110dp"
android:layout_marginTop="80dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu8" />
</TableRow>
<TableRow android:id="#+id/tableRow3" >
<ImageButton
android:id="#+id/menu9"
android:layout_width="60px"
android:layout_height="80px"
android:layout_marginLeft="2dp"
android:layout_marginTop="40dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu9" />
<ImageButton
android:id="#+id/menu10"
android:layout_width="75dip"
android:layout_height="56dip"
android:layout_alignParentLeft="true"
android:layout_marginLeft="2dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu10" />
<ImageButton
android:id="#+id/menu11"
android:layout_width="75dip"
android:layout_height="65dip"
android:layout_alignParentLeft="true"
android:layout_marginLeft="2dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu11" />
<ImageButton
android:id="#+id/menu12"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="100dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu12" />
</TableRow>
</TableLayout>
</RelativeLayout>
Change also the rule as relativeParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM, RelativeLayout.TRUE);
Also add:
//change this.addContentView(adView, relativeParams); by
RelativeLayout rootView = (RelativeLayout)findViewById(R.id.rootview);
rootView.addView(adView, relativeParams);
Change your XML file like this:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TableLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/mainbackgroundipad"
android:orientation="vertical" >
<TableRow android:id="#+id/tableRow1" >
<ImageButton
android:id="#+id/menu1"
android:layout_width="75dip"
android:layout_height="74dip"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="57dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu1" />
<ImageButton
android:id="#+id/menu2"
android:layout_width="75dp"
android:layout_height="59dp"
android:layout_marginLeft="5dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu2" />
<ImageButton
android:id="#+id/menu3"
android:layout_width="75dip"
android:layout_height="63dip"
android:layout_marginLeft="1dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu3" />
<ImageButton
android:id="#+id/menu4"
android:layout_width="60dp"
android:layout_height="83dp"
android:layout_marginRight="100dp"
android:layout_marginTop="50dp"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
android:src="#drawable/menu4" />
</TableRow>
<TableRow android:id="#+id/tableRow2" >
<ImageButton
android:id="#+id/menu5"
android:layout_width="50dp"
android:layout_height="75dp"
android:layout_marginLeft="12dp"
android:layout_marginTop="60dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu5" />
<ImageButton
android:id="#+id/menu6"
android:layout_width="60dp"
android:layout_height="79dp"
android:layout_marginTop="60dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu6" />
<ImageButton
android:id="#+id/menu7"
android:layout_width="60dip"
android:layout_height="86dip"
android:layout_marginLeft="5dp"
android:layout_marginTop="60dp"
android:background="#android:color/transparent"
android:scaleType="fitStart"
android:src="#drawable/menu7" />
<ImageButton
android:id="#+id/menu8"
android:layout_width="75dip"
android:layout_height="50dip"
android:layout_centerVertical="true"
android:layout_marginRight="110dp"
android:layout_marginTop="80dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu8" />
</TableRow>
<TableRow android:id="#+id/tableRow3" >
<ImageButton
android:id="#+id/menu9"
android:layout_width="60px"
android:layout_height="80px"
android:layout_marginLeft="2dp"
android:layout_marginTop="40dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu9" />
<ImageButton
android:id="#+id/menu10"
android:layout_width="75dip"
android:layout_height="56dip"
android:layout_alignParentLeft="true"
android:layout_marginLeft="2dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu10" />
<ImageButton
android:id="#+id/menu11"
android:layout_width="75dip"
android:layout_height="65dip"
android:layout_alignParentLeft="true"
android:layout_marginLeft="2dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu11" />
<ImageButton
android:id="#+id/menu12"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginRight="100dp"
android:layout_marginTop="70dp"
android:background="#android:color/transparent"
android:scaleType="fitXY"
android:src="#drawable/menu12" />
</TableRow>
</TableLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linear"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="match_parent">
</LinearLayout>
</RelativeLayout>
And in java add your adview in the linearlayout.. Hope it must help you