Why do I have two different layout results in the preview and in the emulator of the same phone? I create some AVDs to emulate the Samsung phones, but their previews and AVDs don't correspond..
Here's my xml file:
<?xml version="1.0" encoding="utf-8"?>
<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"
tools:context="ag.myapplication.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#drawable/sfondo"
android:scaleType="fitXY"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="#+id/relativeLayout">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView4"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/tronco1"
android:layout_marginTop="-250dp" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageButton6"
android:src="#drawable/play_h"
android:scaleType="fitCenter"
android:background="#00ffffff"
android:layout_marginBottom="12dp"
android:layout_above="#+id/imageButton7"
android:layout_alignLeft="#+id/imageButton7"
android:layout_alignStart="#+id/imageButton7" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageButton7"
android:src="#drawable/score_h"
android:scaleType="fitCenter"
android:background="#00ffffff"
android:layout_above="#+id/imageButton8"
android:layout_alignLeft="#+id/imageButton8"
android:layout_alignStart="#+id/imageButton8"
android:layout_marginBottom="10dp" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/imageButton8"
android:src="#drawable/options_h"
android:scaleType="fitCenter"
android:background="#00ffffff"
android:layout_above="#+id/imageButton11"
android:layout_centerHorizontal="true"
android:layout_marginBottom="15dp" />
<ImageButton
android:layout_width="170dp"
android:layout_height="50dp"
android:id="#+id/imageButton11"
android:src="#drawable/removeads"
android:scaleType="fitCenter"
android:background="#00ffffff"
android:layout_marginBottom="20dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="400dp"
android:layout_height="200dp"
android:id="#+id/imageView2"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/titolo"
android:layout_marginTop="-10dp" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
Only the ImageButtons are positioned differently, wile the imageViews are where they are supposed to be
Can you help me?
The preview is less reliable than the AVD . You have to base yourself on your emulator display to verify that your view is displayed correctly.
It is preferable to obtain a perfect simulation of the poster of your application will emulate that on a real device.
Related
I have a layout file in my Android application:
<?xml version="1.0" encoding="utf-8"?>
<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="#color/player_background"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".Fragments.PlayerFragment">
<ProgressBar
android:id="#+id/progress_bar_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:theme="#style/ProgressBarStyle"
android:visibility="invisible" />
<TextView
android:id="#+id/title_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Title"
android:textColor="#color/white"
android:textSize="24dp" />
<ImageView
android:id="#+id/view_imageview"
android:layout_width="280dp"
android:layout_height="280dp"
android:layout_marginTop="10dp"
android:background="#color/white" />
<TextView
android:id="#+id/status_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Status"
android:textColor="#color/white"
android:textSize="20dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<ImageButton
android:id="#+id/play_pause_btn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerHorizontal="true"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="#drawable/play_btn" />
<ImageButton
android:id="#+id/sleep_timer_btn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/play_pause_btn"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="#drawable/sleep_btn" />
<ImageButton
android:id="#+id/share_btn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:layout_toLeftOf="#+id/play_pause_btn"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="#drawable/share_btn" />
<TextView
android:id="#+id/sleep_timer_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/sleep_timer_btn"
android:layout_alignLeft="#+id/sleep_timer_btn"
android:layout_alignRight="#+id/sleep_timer_btn"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="Status"
android:textColor="#color/white"
android:textSize="15dp" />
</RelativeLayout>
<SeekBar
android:id="#+id/volume_seek_bar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:theme="#style/Volume_Seekbar"
android:paddingStart="30dp"
android:paddingEnd="30dp"/>
</LinearLayout>
It's working perfectly in most of the devices but in a small screen device I can't see the SeekBar because it's out from the screen. Any idea how I can fix it?
You are using very large fixed sizes on your views, and because different phones got different screen sizes what seems to work on some device will actually not work on another
For example - in a smaller device with height of 300dp with views summing up to total of 400dp you will not have enough room for some views because of the small screen size and that's why you are not seeing your view.
You can use ConstraintLayout to make your screen responsive, or if you want to keep your current layout structure you can use the following libraries for scaling size of dp:
ssp and sdp to get a scalable size unit for your views and texts.
Another option is to wrap your layout with ScrollView, giving your screen the option to be scrollable and by that you will be able to "see" all of your views on your screen - note that this may not be intuitive to your user.
It is because the fixed sizes you are using to build your layout is getting summed up eventually being too big for small screen size. You can try the following to fix this:
Create a layout specially for small screen size by using smallest width qualifier
Make your layout scrollable
Use constraint layout
Using the ssp and sdp size units
NOTE that you will have to specify the smallest width qualifier to your current layout in such a way that the smallest width qualifer excludes the small screen devices and include the devices in which your layout fits properly.
I would suggest you to use constraint layout, but if you still want to go ahead with your current view then it will be good practice if you add scrollview to your parent layout, so that your layout won't get cropped on smaller devices:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/player_background"
android:gravity="center_horizontal"
android:orientation="vertical"
tools:context=".Fragments.PlayerFragment">
<ProgressBar
android:id="#+id/progress_bar_player"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:theme="#style/ProgressBarStyle"
android:visibility="invisible" />
<TextView
android:id="#+id/title_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Title"
android:textColor="#color/white"
android:textSize="24dp" />
<ImageView
android:id="#+id/view_imageview"
android:layout_width="280dp"
android:layout_height="280dp"
android:layout_marginTop="10dp"
android:background="#color/white" />
<TextView
android:id="#+id/status_label"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:gravity="center"
android:text="Status"
android:textColor="#color/white"
android:textSize="20dp" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp">
<ImageButton
android:id="#+id/play_pause_btn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_centerHorizontal="true"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="#drawable/play_btn" />
<ImageButton
android:id="#+id/sleep_timer_btn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginLeft="30dp"
android:layout_toRightOf="#+id/play_pause_btn"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="#drawable/sleep_btn" />
<ImageButton
android:id="#+id/share_btn"
android:layout_width="70dp"
android:layout_height="70dp"
android:layout_marginRight="30dp"
android:layout_toLeftOf="#+id/play_pause_btn"
android:background="#drawable/round_button"
android:gravity="center_vertical|center_horizontal"
android:padding="20dp"
android:scaleType="fitCenter"
android:src="#drawable/share_btn" />
<TextView
android:id="#+id/sleep_timer_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/sleep_timer_btn"
android:layout_alignLeft="#+id/sleep_timer_btn"
android:layout_alignRight="#+id/sleep_timer_btn"
android:layout_marginTop="5dp"
android:gravity="center"
android:text="Status"
android:textColor="#color/white"
android:textSize="15dp" />
</RelativeLayout>
<SeekBar
android:id="#+id/volume_seek_bar"
android:layout_width="match_parent"
android:layout_height="40dp"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:theme="#style/Volume_Seekbar" />
</LinearLayout>
</ScrollView>
I'm running android 5.1.1 on Samsung Galaxy Tab A (2016). I have implemented a webview and androidpdfviewer and i'm experiencing a scroll issue. I am not able to scroll vertically and horizontally. The same implementation works on a Lenovo Tab that is running on Android 6.0.
This is the sample code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="30dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="30dp"
android:background="#color/white"
android:orientation="vertical">
<!-- TOP SECTION WITH HEADER-->
<LinearLayout
android:id="#+id/top_section"
android:layout_width="match_parent"
android:layout_height="24dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="1dp"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<sg.utmobile.core.ui.view.UtTextView
android:id="#+id/text_form_title"
style="#style/General.Component.Text.Header.Fragment"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:tag="text_form_title"
android:text="Document Preview"
android:visibility="visible" />
<View
android:id="#+id/header_line"
style="#style/title_line"
android:tag="header_line" />
</LinearLayout>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="850dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="5dp"
android:gravity="center">
<!-- PDF REGION -->
<!--<com.github.barteksc.pdfviewer.PDFView
android:id="#+id/grid_pdf_viewer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="60dp"
android:isScrollContainer="true"
android:scrollbars="vertical"
android:tag="grid_pdf_viewer"
android:visibility="visible"></com.github.barteksc.pdfviewer.PDFView>-->
<ScrollView
android:layout_width="match_parent"
android:layout_height="850dp">
<sg.utmobile.core.ui.view.UtWebView
android:id="#+id/grid_pdf_viewer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="60dp"
android:overScrollMode="always"
android:tag="grid_pdf_viewer"
android:visibility="visible"></sg.utmobile.core.ui.view.UtWebView>
</ScrollView>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<sg.utmobile.core.ui.view.UtCheckbox
android:id="#+id/chk_read_loan_doc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginLeft="8dp"
android:button="#drawable/custom_checkbox_selector"
android:checked="false"
android:soundEffectsEnabled="false"
android:tag="chk_read_loan_doc" />
<sg.utmobile.core.ui.view.UtTextView
android:id="#+id/txt_read_loan_doc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="3dp"
android:layout_marginTop="2dp"
android:tag="txt_read_loan_doc"
android:text="I have read and understood the loan document"
android:textAllCaps="true"
android:textColor="#color/black"
android:textSize="16dp"
mobile:font="Ubuntu-R" />
<sg.utmobile.core.ui.view.UtButton
android:id="#+id/button_dismiss"
android:layout_width="wrap_content"
android:layout_height="#dimen/component_height_normal"
android:layout_alignParentRight="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="2dp"
android:layout_toRightOf="#id/button_clear"
android:background="#drawable/form_button_selector"
android:paddingLeft="12dp"
android:paddingRight="12dp"
android:singleLine="true"
android:tag="button_dismiss"
android:text="CONFIRM"
android:textAllCaps="true"
android:textColor="#color/text_color_1"
android:textSize="#dimen/text_font_size_normal"
mobile:font="Ubuntu-R" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
In android studio when I see my app in the design view in XML it looks fine to me (just how I want it). But when I run my app on my device which is a Moto G the layout seems to just flop to one side. Why is this?
My Moto G device below (all the views and features flops to the side)
The design view in android studio. Everything looks good.
My XML code below
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:background="#drawable/backgroundpage"
tools:context="xetron.appathon.orbis.landmarks">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="70dp"
android:background="#drawable/bar"
android:id="#+id/relativeLayout">
<TextView
android:text="Landmarks"
android:textStyle="bold"
android:textSize="30sp"
android:textColor="#005491"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_marginLeft="62dp"
android:layout_marginTop="11dp"
android:id="#+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/landmarkName"
android:textStyle="bold"
android:textSize="30sp"
android:textColor="#005491"
android:text="UK"
android:layout_toEndOf="#+id/textView"
android:layout_marginLeft="34dp"
android:layout_alignTop="#+id/textView"
android:layout_toRightOf="#+id/textView" />
</RelativeLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lmkname1"
android:textStyle="bold"
android:textSize="20sp"
android:textColor="#8FCE7B"
android:text="Forbidden
Kingdom"
android:layout_marginLeft="35dp"
android:layout_marginTop="80dp"
/>
<ImageView
android:layout_width="180dp"
android:layout_height="160dp"
android:src="#drawable/lmk1china"
android:layout_below="#+id/relativeLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="57dp"
android:id="#+id/lmkimg1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lmkname2"
android:textStyle="bold"
android:textSize="25sp"
android:textColor="#8FCE7B"
android:text="Shanghai
Tower"
android:layout_marginLeft="210dp"
android:layout_marginTop="80dp"
/>
<ImageView
android:layout_width="180dp"
android:layout_height="160dp"
android:src="#drawable/lmk2china"
android:layout_alignTop="#+id/lmkimg1"
android:layout_alignRight="#+id/relativeLayout"
android:layout_alignEnd="#+id/relativeLayout"
android:id="#+id/lmkimg2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lmkname3"
android:textStyle="bold"
android:textSize="25sp"
android:textColor="#8FCE7B"
android:text="Great Wall
Of China"
android:layout_marginLeft="35dp"
android:layout_marginTop="435dp"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/lmkname4"
android:textStyle="bold"
android:textSize="25sp"
android:textColor="#8FCE7B"
android:text="Temple Of
Heaven"
android:layout_marginLeft="210dp"
android:layout_marginTop="435dp"
/>
<ImageView
android:layout_width="180dp"
android:layout_height="160dp"
android:src="#drawable/lmk3china"
android:layout_below="#+id/lmkimg1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/lmkimg3" />
<ImageView
android:layout_width="180dp"
android:layout_height="160dp"
android:src="#drawable/lmk4china"
android:layout_below="#+id/lmkimg2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginBottom="24dp"
android:id="#+id/lmkimg4"/>
</RelativeLayout>
You should try to create a design with less fixed sizes (e.g. image-size 180dp), because this will never scale well on all screen-sizes. I find it never easy to build a well-scaling layout and you have to test it right away while building.
That said, you can create different layouts, for different screen sizes by appending the size to the xml-filename. This is, however, mainly used to define different layouts for the major screen-sizes: phone, tablet, landscape, portrait. It is not used to define a separate layout for difference in inches.
You must avoid to use "hard" values in dimensions. Use "dip" instead. Also, use weights for elements positioning.
Example:
<LinearLayout
android:id="#+id/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<View
android:layout_width="0dip"
android:layout_height="match_parent"
android:background="#FF0000"
android:layout_weight="1" />
</LinearLayout>
this is my XML:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/LinearLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/very_dark_gray"
android:padding="#dimen/padding_menu_bar_items" >
<ImageView
android:id="#+id/ivRefresh"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:onClick="ivRefresh_click"
android:padding="#dimen/padding_menu_bar_items"
android:src="#drawable/refresh_android96" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="#string/fav"
android:textColor="#color/light_gray"
android:textSize="#dimen/click_text_size" />
<ImageView
android:id="#+id/ivOpenShareLinks"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/ivRefresh"
android:layout_alignParentRight="true"
android:onClick="openShareLinks"
android:padding="#dimen/padding_menu_bar_items"
android:src="#drawable/box_up96" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlMainArea"
android:layout_width="match_parent"
android:layout_height="270dp"
android:layout_weight="1"
android:background="#android:drawable/sym_def_app_icon"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/llCurrentSong"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="26dp"
android:background="#drawable/layout_bg"
android:orientation="vertical"
android:padding="#dimen/padding_menu_bar_items" >
<TextView
android:id="#+id/tvHrefStartStop"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="5.07"
android:clickable="true"
android:onClick="playPause"
android:padding="#dimen/padding_menu_bar_items"
android:text="#string/start_stop"
android:textColor="#color/click_items"
android:textSize="#dimen/click_text_size" />
<TextView
android:id="#+id/tvSongName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="5.07"
android:padding="#dimen/padding_menu_bar_items"
android:textColor="#color/white"
android:textSize="#dimen/click_text_size" />
<ProgressBar
android:id="#+id/pbNowSong"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:layout_weight="5.07" />
<TextView
android:id="#+id/tvArtist"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="5.07"
android:padding="#dimen/padding_menu_bar_items"
android:textColor="#color/white" />
</LinearLayout>
<RelativeLayout
android:id="#+id/rlTopArea"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_above="#+id/llCurrentSong"
android:layout_alignParentRight="true"
android:layout_marginBottom="16dip"
android:background="#drawable/layout_bg" >
<TextView
android:id="#+id/tvBackToMain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:layout_toRightOf="#+id/ivBtnTopLIsten"
android:padding="#dimen/padding_menu_bar_items"
android:text="#string/listens"
android:textColor="#color/click_items" />
<ImageView
android:id="#+id/ivBtnTopLIsten"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:onClick="clickedTopSongsIcon"
android:padding="#dimen/padding_menu_bar_items"
android:src="#android:drawable/ic_menu_sort_by_size" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/rlEmail"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#drawable/email"
android:onClick="clickContactUs"
android:orientation="vertical" >
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="1"
android:background="#drawable/lower_image" >
<TableLayout
android:id="#+id/TableLayoutShare"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#drawable/layout_bg_white_no_radius_conrenrs"
android:padding="#dimen/padding_menu_bar_items" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/ivTwitter"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/tw_icon" />
<ImageView
android:id="#+id/ivFacebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/fb_icon" />
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/twitter"
android:textColor="#color/black" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="#string/facebook"
android:textColor="#color/black" />
</TableRow>
</TableLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_margin="#dimen/padding_menu_bar_items"
android:background="#drawable/layout_bg_black_opacity_radius_corners" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/RelativeLayoutTodayPlaylist"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/relativeLayout1"
android:background="#drawable/layout_bg_black_opacity_only_half_radius_corners"
android:onClick="openListenToday" >
<TextView
android:id="#+id/tvListenThisWeak"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:layout_toLeftOf="#+id/ivLines1"
android:onClick="openListenToday"
android:padding="#dimen/padding_menu_bar_items"
android:text="#string/was_today"
android:textColor="#color/click_items" />
<ImageView
android:id="#+id/ivLines1"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:onClick="clickedTopSongsIcon"
android:padding="#dimen/padding_menu_bar_items"
android:src="#drawable/lines" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/relativeLayout1"
android:layout_alignParentRight="true"
android:background="#drawable/layout_bg_black_opacity_only_half_radius_corners"
android:onClick="openListenThisWeek" >
<TextView
android:id="#+id/tvListenToday"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginRight="16dp"
android:layout_toLeftOf="#+id/ivLines1"
android:onClick="openListenThisWeek"
android:padding="#dimen/padding_menu_bar_items"
android:text="#string/was_this_weak"
android:textColor="#color/click_items" />
<ImageView
android:id="#+id/ivLines1"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:onClick="clickedTopSongsIcon"
android:padding="#dimen/padding_menu_bar_items"
android:src="#drawable/lines" />
</RelativeLayout>
</RelativeLayout>
<com.google.ads.AdView
xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"
ads:testDevices="TEST_EMULATOR, TEST_DEVICE_ID"
ads:loadAdOnCreate="true"/>
</LinearLayout>
I added the google.service jar in this way:
moved the folder: google-play-services_lib
to the main app folder.
then, I entered eclipsed, and imported my app > right click on the app name > Properties > Android > on the Libery Clicked 'Add' > added the Google play service:
http://i.stack.imgur.com/9dHrM.png
got the library in my project:
http://i.stack.imgur.com/1gEq6.jpg
when I'm trying to run my app, this error appear::
(26935): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.manishma/com.manishma.MainActivity}: android.view.InflateException: Binary XML file line #287: Error inflating class com.google.ads.AdView
the unitID is checked (changed the code for the example).
what I'm doing wrong?
You are mixing the 2 ways possible right now to display Admob ads. The first one is based on the Android SDK, the second one is based on Google Play services.
The difference between the 2 implementations are explained in details in the developers documentation
In my opinion Google Play services is still too buggy to be used, but soon this will be the only option left.
In your case you mix both because you are using the XML declarations from the Android SDK but at the same time you are integrating the Google Play Services library. You cannot use both, you need to choose one and follow the developer guide I gave above.
Update
1) If you want to use Google Play services, change your XML with this:
<com.google.android.gms.ads.AdView
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/adView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
ads:adUnitId="MY_AD_UNIT_ID"
ads:adSize="BANNER"/>
2) If you want to use the Android SDK, you have to add the GoogleAdMobAdsSdk jar in your libs folder and remove the Google Play services library.
Those are not the only things to do, manifest files must for example also be updated (see documentation).
I have tried to make a Horizontal scrolling of list of 5 images in my app.I wrote the following XML in my app. The problem that i am facing is it leaves a blank
area to the left and right of the screen ,i.e is blamk area before the image list starts and some blank area after the image list .
XML
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center">
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="20dp"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="20dp"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="20dp"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingRight="20dp"
android:src="#drawable/people" />
</LinearLayout>
</HorizontalScrollView>
Can anyone Help me how to remove this unwanted blank area ?
I tried NagarjunaReddy suggestion, but I got the result as shown in screenshot below.
I got the answer to my question .Actually this blank space is coming because of my mobile system operating system android versin 4.0. I checked my same app in android ver2.3 there i dint get any blank space anyways.
Remove android:paddingRight="20dp" for all the <ImageView>s
try this remove pading for all imageviews android:paddingRight="20dp"
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/people" />
</LinearLayout>
It should have nothing to do with the OS version.
Try this:
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:id="#+id/LinearLayout02"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/people" />
<ImageView
android:id="#+id/imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:src="#drawable/people" />
</LinearLayout>
You should get something like this: