How to set the position of image - android

i am new in android , i am facing problem in setting the image position . i set image position in layout but when i check on device or emulator it changes position.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/lay_ring"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/backfull_a"
android:orientation="vertical" >
<ImageButton
android:id="#+id/id_ringButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="44dp"
android:layout_marginTop="16dp"
android:background="#android:color/transparent"
android:src="#drawable/button_ring" />
<ImageView
android:id="#+id/image_hand_lastACt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:src="#drawable/white" />
<ImageView
android:id="#+id/id_ring_finger"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="144dp"
android:layout_marginRight="70dp"
android:layout_toLeftOf="#+id/id_ringButton"
android:src="#null" />
<ImageView
android:id="#+id/id_fingA_ring"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/id_imgback"
android:layout_marginRight="21dp"
android:layout_marginTop="48dp"
android:src="#drawable/a_style_a" />
<ImageView
android:id="#+id/id_fingB_ring"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/id_ringButton"
android:layout_marginRight="44dp"
android:layout_toLeftOf="#+id/id_fingA_ring"
android:src="#drawable/a_style_b" />
<ImageButton
android:id="#+id/id_next_ring"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/id_ringButton"
android:layout_alignTop="#+id/id_ring_finger"
android:layout_marginTop="46dp"
android:background="#android:color/transparent"
android:src="#drawable/aero_right" />
</RelativeLayout>
i tried but did not find proper solution . give some demo or link that is easily understandable .

android handset has many DPIs. so,you should not set the position too accurate.
You can use some relative description like toRightof / alignPerentRight etc.

Related

how to reduce loading time of Activity?

I am doing following in Activity's onCreate,
if(condition satisfied){
imageView.setImage(passing view to resize);
imageview.setVisibility(View.VISIBLE);
}
else
imageview.setVisibility(View.INVISIBLE);
resizing like below,
Bitmap bmSource = BitmapFactory.decodeResource(context.getResources(), res);
Bitmap bmThumbnail;
bmThumbnail = getResizedBitmap(bmSource, getScreenWidth() / x, (getScreenWidth() / y));
Drawable drawable = new BitmapDrawable(context.getResources(), bmThumbnail);
b.setBackground(drawable);
In this code I mentioned one view.but in actual code I am having multiple views
This Activity(Consider as A) used as three below,
Outgoing Call Screen
Outgoing Call connected screen
Incoming Call connected screen.
so that I am doing changes in Activity according to that. Using images for speaker,mute,record,etc required for call.
OutGoing Call and Call connected Screen,
a)Doing changes for displaying Outgoing call.
b)Once received call acceptance from other person immediately doing screen changes for call connected screen
c)Once screen changes done, timer will be started for call.
Incoming Call connected,
a) For displaying Incoming call screen used different Activity.
b) Once user accepts call, then moving to Activity A.
c) So in Activity A, initially will do some image set up. Once I got response for acceptance image changes for call connected screen will be done.
So thats the overall process. Now will explain about the problem,
I have mentioned that in both the cases call connected screen changes will be done in Activity A.
In first case, as that already in same screen initial image setup will loaded previously and once got response then changes for Call connected screen will be done. Timer will be started. No problem here.
Problem is ,
When answering Incoming call, it will go to Activity A and Initial image setup. Once got acceptance response will change screen to call connected screen and timer starts. Here it takes time to load initial image setup. So starts timer one sec late leads to different time for Person A and Person B
This problem not occurring in all devices. In Android version 8 I experienced this problem not in above version.
What I meant by Initial Image Setup is setting visibility of imageviews and setting images.
What I have tried,
Instead of using Bitmap used Picasso for resizing and setting image. So that I am able to reduce some 0.20 to 0.25 secs. But image is expanded not proper. In above oreo also reduced some 0.x secs. But also not solved the problem.
Also in log, I have seen this
PowerKeeper.Event: notifyActivityLaunchTime: com.package.ex/com.package.ExampleActivity totalTime: 1200
1200 mentioned above is milliseconds taken for launching my Activity?? Sometimes getting 1212, 1400
My app works perfect in above O. But oreo and below takes some time to load that affects the call duration. Its really bad. So what can I do??
So how to reduce time taken for doing UI changes in Activity???
If Anyone find difficulty reading my entire question,then look this short note.
Explained Shortly: Consider you are using a calling app(your device is oreo or lower than oreo).And you receive a Incoming call. You tap on answer. Screen will be changed after successfully connected. What if that screen takes some time to load for you while the person in other end got the screen before you? Call duration for you and the other person will be different. So thats my problem
Note: Facing this problem only in oreo and below verions.
below is my layout for Activity A.(Used as call connected screen and outgoing call screen)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/call_page"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/connected_call_background"
android:descendantFocusability="beforeDescendants"
android:focusableInTouchMode="true">
<RelativeLayout
android:id="#+id/top_bar"
android:layout_width="match_parent"
android:layout_height="60dp"
android:paddingLeft="#dimen/activity_vertical_margin"
android:paddingTop="10dp"
android:paddingRight="#dimen/activity_vertical_margin"/>
<ImageView
android:id="#+id/plain_white_bg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" />
<LinearLayout
android:id="#+id/call_swap_merge_transfer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#id/center_view"
android:background="#297B88"
android:paddingLeft="25dp"
android:paddingRight="25dp"
android:visibility="invisible"
android:weightSum="3">
<ImageView
android:id="#+id/swap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="swapCall" />
<ImageView
android:id="#+id/merge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="mergeCall" />
<ImageView
android:id="#+id/transfer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="attendedCallTransfer" />
</LinearLayout>
<ImageView
android:id="#+id/record_call"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/center_view"
android:layout_centerHorizontal="true"
android:onClick="callRecord"
android:visibility="visible" />
<View
android:id="#+id/center_view"
android:layout_width="match_parent"
android:layout_height="0.01dp"
android:layout_centerInParent="true" />
<ImageView
android:id="#+id/after_call_connected_background"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/center_view"
android:layout_alignParentBottom="true"
android:background="#drawable/bg_dialpad"
android:visibility="invisible" />
<ImageView
android:id="#+id/conference_background"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/bg_dialpad"
android:visibility="invisible" />
<RelativeLayout
android:id="#+id/connected_call_root_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:paddingTop="20dp"
android:paddingStart="40dp"
android:paddingLeft="40dp"
android:paddingEnd="40dp"
android:paddingRight="40dp"
android:paddingBottom="60dp">
<TextView
android:id="#+id/dialling_status"
style="#style/Base.TextAppearance.AppCompat.Small.Inverse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:text="#string/dialling"
android:textColor="#color/white"
android:textSize="15.5sp" />
<TextView
android:id="#+id/call_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentEnd="true"
android:text=""
android:textColor="#color/white" />
<ImageView
android:id="#+id/hangupoutgoingcall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:onClick="hangUpCall" />
<ImageView
android:id="#+id/dialerpadbutton_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:clickable="false"
android:visibility="invisible" />
<ImageView
android:id="#+id/callspeakerbutton_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:onClick="speakerOn"
android:visibility="invisible" />
<View
android:id="#+id/hangup_view"
android:layout_width="match_parent"
android:layout_height=".01dp"
android:layout_above="#+id/hangupoutgoingcall"
android:layout_margin="2dp"
android:visibility="invisible" />
<ImageView
android:id="#+id/dialerpadbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/hangup_view"
android:layout_centerHorizontal="true"
android:layout_margin="10dp"
android:clickable="false"
android:onClick="showKeypad"
android:visibility="invisible" />
<ImageView
android:id="#+id/callspeakerbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/hangup_view"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_margin="10dp"
android:onClick="speakerOn"
android:visibility="invisible" />
<ImageView
android:id="#+id/callmutebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/hangup_view"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_margin="10dp"
android:clickable="false"
android:onClick="muteOn"
android:visibility="invisible" />
<RelativeLayout
android:id="#+id/connected_call_keypad_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/dialerpadbutton"
android:layout_marginLeft="-25dp"
android:layout_marginRight="-25dp">
<ImageView
android:id="#+id/bts1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#id/btzoutgoing" />
<ImageView
android:id="#+id/btzoutgoing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<ImageView
android:id="#+id/bth1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#id/btzoutgoing" />
<ImageView
android:id="#+id/bt71"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bts1"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/bt81" />
<ImageView
android:id="#+id/bt81"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/btzoutgoing"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<ImageView
android:id="#+id/bt91"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bth1"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/bt81" />
<ImageView
android:id="#+id/bt41"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bt71"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/bt51" />
<ImageView
android:id="#+id/bt51"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bt81"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<ImageView
android:id="#+id/bt61"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bt91"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/bt51" />
<ImageView
android:id="#+id/bt11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bt41"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="#id/bt21" />
<ImageView
android:id="#+id/bt21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bt51"
android:layout_centerHorizontal="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp" />
<ImageView
android:id="#+id/bt31"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bt61"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_toRightOf="#id/bt21" />
<View
android:id="#+id/view2"
android:layout_width="match_parent"
android:layout_height="0.005dp"
android:layout_above="#id/bt21"
android:background="#4B4B4B"
android:visibility="invisible" />
<EditText
android:id="#+id/editText1aaa"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/buttonoutgoing"
android:layout_alignBottom="#+id/buttonoutgoing"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:background="#00000000"
android:ellipsize="start"
android:focusable="true"
android:focusableInTouchMode="true"
android:foregroundGravity="center"
android:gravity="center"
android:hint=""
android:paddingRight="10dp"
android:textColor="#color/black80"
android:textCursorDrawable="#null" />
<EditText
android:id="#+id/contact_nameforoutgoing"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_above="#id/view2"
android:layout_alignTop="#+id/buttonoutgoing"
android:layout_alignBottom="#+id/buttonoutgoing"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:background="#00000000"
android:ellipsize="start"
android:enabled="false"
android:focusableInTouchMode="true"
android:foregroundGravity="center"
android:gravity="center"
android:hint=""
android:textColor="#color/black80"
android:textCursorDrawable="#null"
android:textSize="20dp" />
<Button
android:id="#+id/buttonoutgoing"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#id/view2"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_marginRight="25dp"
android:layout_toEndOf="#+id/editText1aaa"
android:layout_toRightOf="#+id/editText1aaa"
android:background="#00000000"
android:onClick="removeNumberFromOutgoingNumber"
android:textColor="#fff"
android:visibility="invisible" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/add_hold_transfer_record_holder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/dialerpadbutton"
android:layout_marginStart="10dp"
android:layout_marginEnd="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="25dp"
android:paddingBottom="10dp">
<ImageView
android:id="#+id/hold"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:clickable="false"
android:enabled="false"
android:onClick="holdOn" />
<ImageView
android:id="#+id/call_transfer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:enabled="false"
android:onClick="unAttendedCallTransfer" />
<ImageView
android:id="#+id/addcall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:enabled="false"
android:gravity="bottom"
android:onClick="addCall"
android:textColor="#color/white" />
<ImageView
android:id="#+id/record_call_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:onClick="callRecord"
android:visibility="invisible" />
</RelativeLayout>
</RelativeLayout>
<ListView
android:id="#+id/listview_status"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/top_bar"
android:layout_centerInParent="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:dividerHeight="-1dp"
android:gravity="center"
android:visibility="invisible" />
</RelativeLayout>
Please anybody help me... Share some ideas to resolve this issue...Thanks in advance
I have a few suggestions:
Use ConstraintLayout, your xml file contains many views and you are using RelativeLayout or LinearLayout and these are used in a nested way, so this layout nesting may impact performance.
Another thing is while using ConstraintLayout use should use layout_constraintDimensionRatio for you ImageView to set the imageView height or width according to the aspect ratio of the image which you are going to load.
So one this is you need to fix either height or width, and the other thing will be calculated by the aspect ratio.
I am just sharing part of ImageView code, It would be like this:
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:layout_width="0dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintDimensionRatio="H,16:9"
android:layout_height="0dp"> </androidx.constraintlayout.widget.ConstraintLayout>
Note the : app:layout_constraintDimensionRatio="H,16:9"
Also, use glide to load images.
And instead of starting a new activity, you should use fragment, we have seen fragment load faster than starting a new activity.
Try the above-mentioned things, and let me know if the issue persists.

Layout used on different resolution devices

I wrote this login layout that fit perfectly on my device. My problem is that on another device will not be displayed correct because specified values are used for top, left margins.
What I need to do to be sure that constrains will be keeped on any device?
P.S. I have images for mdpi, hdpi etc.
The code is:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_login"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:theme="#style/AppTheme.NoActionBar"
tools:context="com.abc.abc.Login"
android:layout_gravity="center_horizontal">
<RelativeLayout android:id="#+id/content_container"
android:layout_width="match_parent"
android:layout_height="710dp"
android:gravity="center_horizontal">
<RelativeLayout android:id="#+id/login_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<ImageView android:id="#+id/login_button"
android:src="#drawable/login"
android:layout_marginTop="588dp"
android:layout_width="360dp"
android:layout_height="53dp" />
<ImageView android:id="#+id/email_and_password"
android:src="#drawable/email_and_password"
android:layout_marginTop="465dp"
android:layout_width="362dp"
android:layout_height="107dp" />
<ImageView android:id="#+id/separator"
android:src="#drawable/separator"
android:layout_marginStart="169dp"
android:layout_marginTop="412dp"
android:layout_width="25dp"
android:layout_height="12dp" />
<ImageView android:id="#+id/facebook_button"
android:src="#drawable/facebook"
android:layout_marginTop="383dp"
android:layout_width="166dp"
android:layout_height="66dp" />
<ImageView android:id="#+id/google_button"
android:src="#drawable/google"
android:layout_marginStart="196dp"
android:layout_marginTop="383dp"
android:layout_width="166dp"
android:layout_height="66dp" />
<ImageView android:id="#+id/dont_have_an_account"
android:src="#drawable/dont_have_an_account"
android:layout_marginStart="54dp"
android:layout_marginTop="665dp"
android:layout_width="255dp"
android:layout_height="19dp" />
<ImageView android:id="#+id/logo"
android:src="#drawable/logo1"
android:layout_marginTop="80dp"
android:layout_width="220dp"
android:layout_height="219dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
</RelativeLayout>
Try not to use marginTop on all the views. Instead set the top most view with a marginTop and then all the images below them can be placed by android:layout_below="<imagView id>" and with some marginTop relative to the view above and not the parent.
You can check this answer

Android FancyCoverFlow - Centered Image has Off-Set on old/smaller Device

I have a problem with the FancyCoverFlow which extends Gallery:
https://github.com/davidschreiber/FancyCoverFlow
I want to center the selected Image of the FancyCoverFlow. On my 5" Android 4.2 Device it works perfectly. But on my 3.7" Android 2.2 the selected Image has an Off-Set to the left.
(I prepaired Images, but I can't post them until I does have 10 Reputations xD)
My FancyCoverFlow Item in XML looks like this:
<package.FancyCoverFlow
android:id="#+id/fancyCoverFlow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
fcf:maxRotation="55"
fcf:scaleDownGravity="0.8"
fcf:unselectedAlpha="0.3"
fcf:unselectedSaturation="0.0"
fcf:unselectedScale="0.2" >
</package.FancyCoverFlow>
The layout of the item I'm displaying in this FancyCoverFlow looks like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
>
<ImageView
android:id="#+id/horizontal_player_image"
android:layout_width="100dp"
android:layout_height="100dp"
android:scaleType="fitCenter"
android:layout_above="#+id/relatLayout"
/>
<RelativeLayout
android:id="#+id/relatLayout"
android:layout_width="100dp"
android:layout_height="20dp"
android:layout_above="#+id/horizontal_player_name">
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_marginLeft="5dp"
android:src="#drawable/drinkplayeritem"
android:layout_centerVertical="true"
android:adjustViewBounds="true"/>
<package.BrushTextView
style="#style/BrushFont"
android:id="#+id/horizontal_drink_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:layout_centerVertical="true"
android:text=""
android:gravity="left"
android:layout_toRightOf="#+id/imageView1"
/>
<package.BrushTextView
style="#style/BrushFont"
android:id="#+id/horizontal_false_card_count"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#android:color/white"
android:layout_centerVertical="true"
android:text=""
android:gravity="right"
android:layout_toLeftOf="#+id/imageView2"
/>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:adjustViewBounds="true"
android:src="#drawable/cardsplayeritem" />
</RelativeLayout>
<package.BrushTextView
style="#style/BrushFont"
android:id="#+id/horizontal_player_name"
android:layout_width="100dp"
android:layout_height="20dp"
android:textColor="#android:color/white"
android:layout_alignParentBottom="true"
android:gravity="center_horizontal"
android:textSize="15sp"
/>
</RelativeLayout>
I already tried center everything I've found :D ImageViews (FitCenter) etc...
Nothing worked. It is so stupid that it works on my newer Device but on the older one not..
Hope someone can help me and maybe had the same issue.
EDIT 1:
Does it results of the deprecated class Gallery? But if so, why does it work on my newer device? :D
Thanks!

Android / XML : Referring to a element which is declared later

eclipse shows me an error when I'm referring to a element that is declared later. How can I solve this or is there any kind of work around. Here is the part of my xml-layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:padding="5dp">
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="#id/imageView1" <!-- error -->
android:layout_alignParentLeft="true"
android:layout_alignTop="#id/imageView1" <!-- error -->
android:layout_centerVertical="true" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#id/checkBox1"
android:src="#drawable/folder" />
I want the ImageView to be to the right of the checkbox, but I also want the checkBox to be as "high" as the ImageView (the checkbox should be still a square)
regards
#kalyan pvs....it is ok but you should not call each time with "#+id" which means you are creating new instance each time. This is wrong way of referring to an item in relative layout. In this, rendering errors will come when you are referring to a view which will be created after the present view. The right way of calling reference is #id only.
Just swap the CheckBox and the ImageView and remove android:layout_toRightOf="#+id/checkBox1" from the ImageView (in order to avoid a circular reference):
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:src="#drawable/folder"
/>
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="#id/imageView1"
android:layout_alignParentLeft="true"
android:layout_alignTop="#id/imageView1"
android:layout_centerVertical="true"
/>
Otherwise, the CheckBox can't refer the ImageView's id, since it hasn't been created yet
[EDIT]
An even better way to do that is incorporating the ImageView into the CheckBox, as a compound drawable:
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:drawableRight="#drawable/folder"
android:layout_drawablePadding="10dp"
/>
Note that now the image is on the right side of the checkbox.
This is a best practice.
Declaring a View later is not a problem, Try this, Reduced some lines of your code.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF"
android:padding="5dp" >
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
/>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/checkBox1"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
Something like this works for me:
<?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="#FFFFFF"
android:padding="5dp">
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/imageView1"
android:layout_centerVertical="true" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:layout_toRightOf="#+id/checkBox1"
android:src="#drawable/folder" />
</RelativeLayout>

How to define two different layouts for the layouts in the same category but slightly different inches?

I am testing my layout in eclipse's graphical layout. There are 5.4in FWVGA(480x854,mdpi) and 5.1in WVGA(480x800,mdpi) screens available to view in the graphical layout. If I am correct they both fall into large screen category, therefore I've put the layout xml into layout-large folder. And I've put my images into drawable-large-mdpi folder. But the image buttons are slightly off in 5.1in WVGA as you can see in the screenshots below. First is 5.1in, the second screenshot is 5.4'' and the correct one.
My second question which is similar to the above goes like this. I've done new layout for the Nexus 7 and put it into layout-sw600dp folder, and images to the drawable-tvdpi. Then I viewed this layout in the 7in tablet (1024x600,mdpi). And the image buttons are slightly off than it should look. The same way as in the first question.
I understand that the reason is probably because 5.1in and 5.4in isn't exactly the same even though they fall into the same category and I should have 2 different layouts for them. So how I should go about it? How can I have two different layouts? Or is there better solution, as I don't want to create a layout for each screen size that exist on the market.
Here is xml file:
<?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="match_parent"
android:background="#drawable/wall4_cabinetclosed" android:orientation="vertical">
<RelativeLayout android:id="#+id/frames_layout"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginLeft="73dp" android:layout_marginTop="57dp">
<ImageView android:id="#+id/fire_frame"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignParentLeft="true" android:layout_alignParentTop="true"
android:background="#drawable/small_fire_icon" />
<ImageView android:id="#+id/water_frame"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignTop="#+id/fire_frame" android:layout_marginLeft="75dp"
android:layout_toRightOf="#+id/fire_frame" android:background="#drawable/small_water_icon" />
<ImageView android:id="#+id/earth_frame"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="#+id/fire_frame" android:layout_marginTop="71dp"
android:layout_toLeftOf="#+id/water_frame" android:background="#drawable/small_earth_icon" />
<ImageView android:id="#+id/wind_frame"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignLeft="#+id/water_frame" android:layout_alignTop="#+id/earth_frame"
android:background ="#drawable/small_wind_icon" />
</RelativeLayout>
<ImageView android:id="#+id/zoomed_image"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<Button android:id="#+id/frames" android:layout_width="210dp"
android:layout_height="220dp" android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" android:layout_marginLeft="55dp"
android:layout_marginTop="30dp" android:onClick="zoomFrames"
android:background="#android:color/transparent"/>
<Button android:id="#+id/blue" android:layout_width="115dp"
android:layout_height="70dp" android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true" android:layout_marginLeft="220dp"
android:onClick="zoomImage"
android:background="#android:color/transparent"/>
<Button android:id="#+id/white" android:layout_width="85dp"
android:layout_height="50dp" android:layout_alignParentRight="true"
android:layout_alignParentTop="true" android:layout_marginRight="420dp"
android:layout_marginTop="420dp" android:onClick="zoomImage"
android:visibility="invisible"
android:background="#android:color/transparent"/>
<ImageView
android:id="#+id/fireplace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="311dp"
android:layout_marginLeft="67dp"
android:background="#drawable/fire"
/>
<ImageButton
android:id="#+id/water_room"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="310dp"
android:layout_marginLeft="90dp"
android:background="#drawable/view_water_room"
android:onClick="finishFireRoom"
android:visibility="gone"
/>
<ImageView android:id="#+id/frames_zoomed_image"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:background="#drawable/frames_zoomed" android:onClick="hideZoomedFrames"
android:visibility="gone"/>
<RelativeLayout android:id="#+id/frameZoomedLayout"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_marginTop="113dp" android:layout_marginLeft="145dp"
android:visibility="gone"
>
<ImageButton android:id="#+id/fire_icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:background="#drawable/fire_icon" android:onClick="changeIcon" />
<ImageButton android:id="#+id/water_icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignBottom="#+id/fire_icon" android:layout_toRightOf="#+id/fire_icon"
android:background="#drawable/water_icon" android:layout_marginLeft="147dp" android:onClick="changeIcon"/>
<ImageButton android:id="#+id/earth_icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="#+id/fire_icon" android:layout_marginTop="140dp"
android:layout_toLeftOf="#+id/water_icon" android:background="#drawable/earth_icon" android:onClick="changeIcon"/>
<ImageButton android:id="#+id/wind_icon"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_alignLeft="#+id/water_icon" android:layout_alignTop="#+id/earth_icon"
android:background="#drawable/wind_icon" android:onClick="changeIcon"/>
</RelativeLayout>
</RelativeLayout>
in 3rd step set all ur device specific like screen, language etc all. and ur done

Categories

Resources