Android Admob - Didn't find class "com.google.ads.AdView" - java

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).

Related

android studio unable to start activity ComponentInfo

java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.joystick.myapplication/com.example.joystick.myapplication.MainActivity}:
android.view.InflateException: Binary XML file line #2: Binary XML
file line #2: Error inflating class
android.support.constraint.ConstraintLayout
i keep getting this error
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="0dp">
<Button
android:id="#+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/writeMsg"
android:layout_alignBottom="#+id/writeMsg"
android:layout_toEndOf="#+id/onOff"
android:layout_toRightOf="#+id/onOff"
android:text="Send"
tools:layout_editor_absoluteX="139dp"
tools:layout_editor_absoluteY="111dp" />
<ListView
android:id="#+id/peerListView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
tools:layout_editor_absoluteX="8dp"
tools:layout_editor_absoluteY="260dp" />
<EditText
android:id="#+id/writeMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="63dp"
android:layout_marginStart="63dp"
android:layout_toEndOf="#+id/back"
android:layout_toRightOf="#+id/back"
android:ems="10"
android:inputType="textPersonName"
tools:layout_editor_absoluteX="35dp"
tools:layout_editor_absoluteY="429dp" />
<Button
android:id="#+id/onOff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/connectionStatus"
android:layout_marginLeft="75dp"
android:layout_marginStart="75dp"
android:layout_toEndOf="#+id/readMsg"
android:layout_toRightOf="#+id/readMsg"
android:text="Wifi On"
tools:layout_editor_absoluteX="73dp"
tools:layout_editor_absoluteY="77dp" />
<Button
android:id="#+id/discover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/readMsg"
android:layout_alignRight="#+id/readMsg"
android:layout_below="#+id/connectionStatus"
android:text="discover"
tools:layout_editor_absoluteX="155dp"
tools:layout_editor_absoluteY="0dp" />
<TextView
android:id="#+id/readMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/writeMsg"
android:layout_alignEnd="#+id/writeMsg"
android:layout_alignRight="#+id/writeMsg"
android:layout_marginBottom="24dp"
android:layout_marginEnd="65dp"
android:layout_marginRight="65dp"
android:text="Message"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="italic"
tools:layout_editor_absoluteX="132dp"
tools:layout_editor_absoluteY="373dp" />
<TextView
android:id="#+id/connectionStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="Connection Status"
android:textAlignment="center"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:textStyle="italic"
tools:layout_editor_absoluteX="0dp"
tools:layout_editor_absoluteY="16dp" />
<Button
android:id="#+id/back"
style="#style/Widget.AppCompat.Button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#drawable/back"
android:visibility="visible" />
</RelativeLayout>
It is a long shot but i think that you are trying to load a big(size in MB) picture. What I can recommend is to reduce the size of the picture with 50% and I think your problem it will be fixed.
Goodluck :)
EDIT:
Here is how it looks when i runt it on 5.5 inch device:
It is running good also oon my phone. So please check the MB size of the following pictures:
"#drawable/drone
and
"#drawable/image_button_bg"
EDIT:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/sendButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/writeMsg"
android:layout_alignBottom="#+id/writeMsg"
android:layout_toEndOf="#+id/onOff"
android:text="Send"/>
<ListView
android:id="#+id/peerListView"
android:layout_width="match_parent"
android:layout_height="200dp"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"/>
<EditText
android:id="#+id/writeMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginStart="63dp"
android:layout_toEndOf="#+id/back"
android:ems="10"
android:inputType="textPersonName"/>
<Button
android:id="#+id/onOff"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/connectionStatus"
android:layout_marginStart="75dp"
android:layout_toEndOf="#+id/readMsg"
android:text="Wifi On" />
<Button
android:id="#+id/discover"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/readMsg"
android:layout_below="#+id/connectionStatus"
android:text="discover"/>
<TextView
android:id="#+id/readMsg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/writeMsg"
android:layout_alignEnd="#+id/writeMsg"
android:layout_marginBottom="24dp"
android:layout_marginEnd="65dp"
android:text="Message"
android:textAlignment="center"
android:textSize="20sp"
android:textStyle="italic"/>
<TextView
android:id="#+id/connectionStatus"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="Connection Status"
android:textAlignment="center"
android:textColor="#android:color/holo_blue_dark"
android:textSize="18sp"
android:textStyle="italic"/>
<Button
android:id="#+id/back"
style="#style/Widget.AppCompat.Button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#drawable/back"
android:visibility="visible" />
</RelativeLayout>
Ty this as XML and see what happens. If you still getting the error it means that the problem is somewhere else.

My EditText is cut off SMS app

my problem is that my text is cut :/
and I would like something like
here is my edittext :
<?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.support.v7.widget.Toolbar
android:id="#+id/tool_bar_messa"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#f4f4f4"
android:visibility="visible">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="#string/Contact"
android:textColor="#000"
android:textSize="30sp"
android:theme="#android:style/DeviceDefault.ButtonBar.AlertDialog"
android:id="#+id/tv_toolbar"
android:singleLine="true"
android:ellipsize="end" />
<TextView
android:id="#+id/tvDetails"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:singleLine="false"
android:text="#string/Details"
android:textColor="#3391e4"
android:textSize="20sp"
android:theme="#android:style/DeviceDefault.ButtonBar.AlertDialog" />
</android.support.v7.widget.Toolbar>
<ListView
android:id="#+id/lv_message"
android:layout_width="match_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:divider="#null"
android:dividerHeight="0dp"
android:stackFromBottom="false"
android:windowSoftInputMode="adjustResize" />
<RelativeLayout
android:id="#+id/layout_send"
android:background="#FFF"
android:layout_width="match_parent"
android:layout_height="46dp">
<EditText
android:id="#+id/Et_message"
android:layout_width="294dp"
android:hint="#string/sms_mms"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="bottom"
android:inputType="textMultiLine|textCapSentences"
android:scrollHorizontally="false"
android:scrollbars="vertical"
android:textCursorDrawable="#null" />
<ImageButton
android:id="#+id/btnSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/Et_message"
android:layout_toEndOf="#+id/Et_message"
android:layout_toRightOf="#+id/Et_message"
android:background="#00ffffff"
android:src="#drawable/btnsend" />
</RelativeLayout>
</LinearLayout>
and this is before open keyboard then photo I modify some thing about my listview to start the bottom and resize it when keyboard is open stuff like that, maybe it's the problem ?
just remove android:lines="2" and it solve. and you want all the lines to show then also remove android:maxLines="3".
<EditText
android:id="#+id/Et_message"
android:layout_width="294dp"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_gravity="bottom"
android:hint="Type here"
android:inputType="textMultiLine|textCapSentences"
android:scrollHorizontally="false"
android:scrollbars="vertical"
android:maxLines="3"
android:textCursorDrawable="#null" />
this is working correctly.

How to fit my Layout to any Screen in Android

I'm building my own application game for Android, it's a Tic Tac Toe game.
my activities contains mostly ImageViews , all the images placed in the dir res\drawable-mdpi ONLY.
the rest of the drawable folders are empty.
my problem is that when i run the app on a 5.4 inch MDPI screen it works fine and it looks like this:
but when i run the app on another screen of different size for example this 4.65 inch XHDPI screen, it looks like this:
in the above activity i used LinearLayout and RelativeLayout, what should i do to fit my layout to any screen ?
thanks
thanks for editting the pictures
this is the code of the xml file of activity_board.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/board_page_bg"
android:gravity="center" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:background="#drawable/board"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginLeft="30dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/players_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="2dp"
android:text="#string/playersName"
android:textSize="30sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/players_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="5dp"
android:text="#string/playersPoints"
android:textSize="25sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<TextView
android:id="#+id/machines_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="172dp"
android:layout_marginTop="5dp"
android:text="#string/machinePoints"
android:textSize="25sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="right" >
<TextView
android:id="#+id/machines_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="50dp"
android:onClick="openChat"
android:clickable="true"
android:text="#string/machineName"
android:textSize="30sp" />
</RelativeLayout>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp" >
<ImageView
android:id="#+id/block1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:onClick="touch"
android:src="#drawable/block_1_empty" />
<ImageView
android:id="#+id/block2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="155dp"
android:onClick="touch"
android:src="#drawable/block_2_empty" />
<ImageView
android:id="#+id/block3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="310dp"
android:onClick="touch"
android:src="#drawable/block_3_empty" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="40dp" >
<ImageView
android:id="#+id/block4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:onClick="touch"
android:src="#drawable/block_4_empty" />
<ImageView
android:id="#+id/block5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="10dp"
android:onClick="touch"
android:src="#drawable/block_5_empty" />
<ImageView
android:id="#+id/block6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="310dp"
android:layout_marginTop="10dp"
android:onClick="touch"
android:src="#drawable/block_6_empty" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="55dp" >
<ImageView
android:id="#+id/block7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:onClick="touch"
android:src="#drawable/block_7_empty" />
<ImageView
android:id="#+id/block8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="155dp"
android:onClick="touch"
android:src="#drawable/block_8_empty" />
<ImageView
android:id="#+id/block9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="315dp"
android:onClick="touch"
android:src="#drawable/block_9_empty" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="6dp" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/game_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="105dp"
android:text="#string/gameNumber"
android:textSize="25sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/count_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="390dp"
android:text="#string/countDown"
android:textSize="25sp" />
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/end_game"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/EndGame"
android:onClick="endGame"
android:src="#drawable/endgame_btn_1" />
</LinearLayout>
</LinearLayout>
Are you using RelativeLayout?
You should
1. use RelativeLayout as the base container
2. put the "Player" and "System" score inside the same horizontal LinearLayout so that they won't overlap
3. Put the "End game" button as an element which align parent bottom
The screenshots you attached shows that it's a problem caused by the soft status bar. RelativeLayout would help and you should try to prevent hard-coding the dimensions in numbers but making the auto-adjust in RelativeLayout using margins, "layout_toLeftOf", "layout_toRightOf" and etc.
Create a drawable folder, just the word "drawable", in res and put your game images in there. That will make the game images the same across every device density.
Without looking at your XML, I would agree that you're probably using hardcoded dp values instead of sizing the layout with math, ie, weights, match_parent, alignParentRight, etc.
I have adjusted your XML to be easier. I did not plug it into a previewer or anything.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/board_page_bg"
android:gravity="center" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:layout_marginLeft="ADJUST ME"
android:layout_marginRight="ADJUST ME"
android:background="#drawable/board"
android:orientation="vertical" >
<!-- Scoreboard -->
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp" >
<TextView
android:id="#+id/players_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="2dp"
android:layout_alignParentLeft="true"
android:text="#string/playersName"
android:textSize="30sp" />
<TextView
android:id="#+id/players_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="150dp"
android:layout_marginTop="5dp"
android:layout_toLeftOf="#id/players_name"
android:text="#string/playersPoints"
android:textSize="25sp" />
<TextView
android:id="#+id/machines_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="172dp"
android:layout_marginTop="5dp"
android:layout_toRightOf="#id/machines_name"
android:text="#string/machinePoints"
android:textSize="25sp" />
<TextView
android:id="#+id/machines_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="50dp"
android:onClick="openChat"
android:layout_alignParentRight="true"
android:clickable="true"
android:text="#string/machineName"
android:textSize="30sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/block1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="touch"
android:src="#drawable/block_1_empty" />
<ImageView
android:id="#+id/block2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="touch"
android:src="#drawable/block_2_empty" />
<ImageView
android:id="#+id/block3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="touch"
android:src="#drawable/block_3_empty" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/block4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="touch"
android:src="#drawable/block_4_empty" />
<ImageView
android:id="#+id/block5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="touch"
android:src="#drawable/block_5_empty" />
<ImageView
android:id="#+id/block6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="touch"
android:src="#drawable/block_6_empty" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<ImageView
android:id="#+id/block7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="touch"
android:src="#drawable/block_7_empty" />
<ImageView
android:id="#+id/block8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="touch"
android:src="#drawable/block_8_empty" />
<ImageView
android:id="#+id/block9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="touch"
android:src="#drawable/block_9_empty" />
</LinearLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="ADJUST ME" >
<TextView
android:id="#+id/game_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:text="#string/gameNumber"
android:textSize="25sp" />
<TextView
android:id="#+id/count_down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="#string/countDown"
android:textSize="25sp" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/end_game"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/EndGame"
android:onClick="endGame"
android:src="#drawable/endgame_btn_1" />
</LinearLayout>
</LinearLayout>

Android views layout

I took some code from an example application and I need help rearranging it. I'm trying to make a simple mp3 player. Everything works on a small screen. However, when it is rotated or if the screen size is bigger, the layout is all off. I don't know why this is happening. Please help. Thanks so much. My layout:
<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: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=".MainActivity" >
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="14dp"
android:onClick="forward"
android:src="#android:drawable/ic_media_ff" />
<ImageButton
android:id="#+id/imageButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/imageButton2"
android:layout_marginLeft="22dp"
android:layout_toRightOf="#+id/imageButton2"
android:onClick="rewind"
android:src="#android:drawable/ic_media_rew" />
<ImageButton
android:id="#+id/imageButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton1"
android:layout_marginLeft="14dp"
android:layout_toRightOf="#+id/imageButton1"
android:onClick="pause"
android:src="#android:drawable/ic_media_pause" />
<ImageButton
android:id="#+id/imageButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageButton3"
android:layout_marginLeft="24dp"
android:layout_toRightOf="#+id/imageButton3"
android:onClick="play"
android:src="#android:drawable/ic_media_play" />
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/imageButton3"
android:layout_toLeftOf="#+id/textView2"
android:layout_toRightOf="#+id/textView1" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/imageButton3"
android:layout_alignTop="#+id/seekBar1"
android:text="#string/inital_Time"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageButton4"
android:layout_alignTop="#+id/seekBar1"
android:text="#string/inital_Time"
android:textAppearance="?android:attr/textAppearanceSmall" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
/>
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
</LinearLayout>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView1"
android:layout_centerHorizontal="true"
android:minLines="2"
android:text=" " />
<ImageView
android:id="#+id/imageView2"
android:layout_width="100px"
android:layout_height="100px"
android:layout_alignLeft="#+id/imageView1"
android:layout_centerVertical="true"
android:onClick="previous"
android:rotation="180"
android:src="#drawable/go_next_black" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="100px"
android:layout_height="100px"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/seekBar1"
android:onClick="next"
android:src="#drawable/go_next_black" />
</RelativeLayout>
To manage layouts possibly to run on all the devices, please use LinearLayout with layout_weight functionality.

horizontal scrolling for list of images

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:

Categories

Resources