how to reduce loading time of Activity? - android

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.

Related

Design layout display is not the same

How to edit xml file layout. All display screen is the same.
screen size 4.7", 5.0" display accuracy. But screen other than this. Display Distortion. Except screen tablet.
Help me fix it.
screen_main.xml
<FrameLayout 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="jp.vertice.test.MainScreenFragment">
<!-- TODO: Update blank fragment layout -->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#51c8fc">
<ImageView
android:layout_width="200dp"
android:layout_height="195dp"
android:id="#+id/imageView2"
android:src="#mipmap/ic_launcher"
android:background="#fc0c0c"
android:layout_marginLeft="18dp"
android:layout_marginStart="18dp"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/btn1"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/btn3"
android:layout_alignStart="#+id/btn3" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/btn2"
android:layout_below="#+id/btn1"
android:layout_alignLeft="#+id/btn1"
android:layout_alignStart="#+id/btn1" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/btn5"
android:layout_below="#+id/btn2"
android:layout_alignLeft="#+id/imageView2"
android:layout_alignStart="#+id/imageView2"
android:layout_marginTop="5dp" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/btn4"
android:layout_alignTop="#+id/btn5"
android:layout_toRightOf="#+id/btn5"
android:layout_toEndOf="#+id/btn5"
android:layout_marginLeft="9dp"
android:layout_marginStart="9dp" />
<ImageButton
android:layout_width="100dp"
android:layout_height="100dp"
android:id="#+id/btn3"
android:layout_alignTop="#+id/btn4"
android:layout_toRightOf="#+id/btn4"
android:layout_toEndOf="#+id/btn4"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="205dp"
android:background="#F4F4F4"
android:layout_gravity="bottom">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="YYYY.MM.DD"
android:id="#+id/txt1"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="22dp"
android:layout_marginStart="22dp"
android:layout_marginBottom="173dp" />
<TextView
android:layout_width="230dp"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
android:id="#+id/text2"
android:layout_alignTop="#+id/txt1"
android:layout_alignLeft="#+id/txt1"
android:layout_alignStart="#+id/txt1"
android:layout_marginTop="25dp" />
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="BUTTON"
android:id="#+id/btn6"
android:layout_marginLeft="11dp"
android:layout_marginStart="11dp"
android:layout_alignTop="#+id/text2"
android:layout_toRightOf="#+id/text2"
android:layout_toEndOf="#+id/text2" />
<TextView
android:layout_width="fill_parent"
android:layout_height="20dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="FOOTER"
android:id="#+id/textView2"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textSize="10sp"
android:textStyle="bold"
android:textAlignment="center"
android:gravity="center_vertical"
android:background="#FFFFFF" />
</RelativeLayout>
</FrameLayout>
Don't use Frame Layout here because Frame Layout used to show single view.
I see you are using fixed dp values for layout_width and layout_height.
dp means density independent pixel. It is not a size independent pixel.
The dp makes sure your layout looks the same on devices with the same size, but different pixel density. It will not look the same on bigger devices.
If you want it to scale to larger devices you will have to use match_parent and wrap_content.
Use the power of the relative layout to place items on the right side of the screen also.
You can also make separate layout files for differently sized devices. So you can customise it depending on the size.
You do this by making a new layout folder named for example layout-sw600dp/ (or any number you want) which will only be used on devices that have at least the width you specified (so 600dp in this example).
Make sure your layout file has the same name in this folder as in the normal folder.
You can find very useful information about this in the documentation:
here and here.
You can try using a GridLayout. This way, the image columns will fill the whole screen.
you can't work with dp and expect the same result on different
if you want same display for all the devices you can work with weightSum and weight here is a little example
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:id="#+id/layout1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>

Android: ImageView display fail with big size

I have a problem with ImageView as below:
I have an image with big size (bigger than its part in screen), when I set src for imageView as:
<ImageView
android:id="#+id/splash_second_iv_right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:src="#drawable/phone_white"
android:layout_toLeftOf="#id/middle"
android:visibility="visible"
android:padding="0dp"
android:layout_marginBottom="0dp"/>
then I put it into a RelativeLayout, problem is the content of image is displayed as wrap in the ImageView but size of ImageView is very big (seems as it auto create padding in the image view in four sides of ImageView, since my calculation for layout fails (can not align property position of child)).
Anybody can tell me what's the problem in here and how do I resolve this problem?
Please have a look at the image to have a better understanding. Also I added attribute:
android:adjustViewBounds="true"
android:scaleType="fitEnd"
I can align the content as I want but size of ImageView still very big.
The xml file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
android:id="#+id/splash_slide_forth">
<TextView
android:id="#+id/splash_forth_tv_title"
android:paddingLeft="60dp"
android:paddingRight="60dp"
android:layout_centerHorizontal="true"
android:gravity="center_horizontal"
android:text="#string/splash_4th_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:textColor="#2b333b"
android:layout_marginTop="40dp"
android:textSize="28sp"
/>
<TextView
android:gravity="center_horizontal"
android:layout_below="#id/splash_forth_tv_title"
android:id="#+id/splash_forth_tv_desc"
android:paddingLeft="60dp"
android:paddingRight="60dp"
android:layout_centerHorizontal="true"
android:text="#string/splash_4th_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#2b333b"
android:layout_marginTop="10dp"
android:textSize="15sp"
/>
<ImageView
android:layout_below="#id/splash_forth_tv_desc"
android:id="#+id/splash_forth_iv_vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/phone_vertical"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:scaleType="fitEnd"
android:adjustViewBounds="true"
android:visibility="gone"
/>
<ImageView
android:layout_below="#id/splash_forth_tv_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/splash_forth_iv_horizontal"
android:src="#drawable/horizontal_phone"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:scaleType="fitEnd"
android:visibility="visible"
/>
Please set image as background,
<ImageView
android:id="#+id/splash_forth_iv_horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_below="#id/splash_forth_tv_desc"
android:layout_centerHorizontal="true"
android:adjustViewBounds="true"
android:scaleType="fitEnd"
android:background="#drawable/demo_image"
android:visibility="visible" />
I really wish it works for you,otherwise we will do something else.

How to set the position of image

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.

Layout optimisation Android

I have a ListView with the following layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:inevent="http://schemas.android.com/apk/lib/com.estudiotrilha.inevent.view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingBottom="8dp"
android:id="#+id/list_events"
android:addStatesFromChildren="true" >
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="180dp"
android:padding="1dp"
android:background="#drawable/post" >
<ImageView
android:id="#+id/imageEventCover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="#drawable/event_cover"
android:scaleType="centerCrop" />
<ProgressBar
android:id="#+id/progressBar"
style="?android:attr/progressBarStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:visibility="gone"
android:layout_marginTop="25dp" />
<com.estudiotrilha.inevent.view.NewTextView
android:id="#+id/textIsEnrolled"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="5dp"
android:text="ENROLLED"
android:textColor="#color/infoText"
inevent:textFor="small"
android:background="#color/infoBoxRed"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_margin="10dp" />
<RelativeLayout android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#drawable/event_mark"
android:layout_marginBottom="12dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:paddingTop="10dp"
android:paddingBottom="10dp" >
<com.estudiotrilha.inevent.view.NewTextView
android:id="#+id/textEventName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lisbon Challenge"
inevent:textFor="h3"
android:paddingBottom="10dip"/>
<ImageView
android:id="#+id/imageCalendar"
android:layout_below="#+id/textEventName"
android:layout_width="18dp"
android:layout_height="18dp"
android:contentDescription="#string/facebookHolder"
android:src="#drawable/ic_action_go_to_today" />
<com.estudiotrilha.inevent.view.NewTextView
android:id="#+id/textEventDuration"
android:layout_below="#+id/textEventName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="#+id/imageCalendar"
android:layout_marginLeft="5dp"
android:textColor="#555"
inevent:textFor="small"
android:text="MAI 05-11, 2014" />
<ImageView
android:layout_below="#+id/textEventName"
android:layout_width="18dp"
android:layout_height="18dp"
android:layout_toLeftOf="#+id/textEventPlace"
android:contentDescription="#string/facebookHolder"
android:src="#drawable/ic_action_place" />
<com.estudiotrilha.inevent.view.NewTextView
android:layout_below="#+id/textEventName"
android:id="#+id/textEventPlace"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginLeft="5dp"
android:textColor="#555"
inevent:textFor="small"
android:text="Lisbon, Portugal" />
</RelativeLayout>
</RelativeLayout>
<View android:layout_width="fill_parent"
android:layout_marginRight="2dp"
android:layout_marginLeft="2dp"
android:layout_height="3dp"
android:background="#drawable/shadow"/>
</LinearLayout>
In that ListView, will be placed several items with images.
Here is a sample of the real deal:
The problem is that all images are loaded asynchronously.
I am using Universal Image Loader to load those images.
What should I do to optimise the list?
Thanks.
Scrolling fast is known as 'flinging', and it will naturally be quite intensive on a list that loads images dynamically (from web or local store), so the only way to deal with it on a mobile platform is to
a) improve user experience by adding a temporary 'loading image:
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showImageOnLoading(R.drawable.ic_stub) // resource or drawable
.build();
b) Simply do not attempt any process intensive rendering when a fling is occuring. The screen moves too fast for anything useful to be rendered anyway, so you might as well wait until the screen is not moving before attempting to render anything:
boolean pauseOnScroll = false; // or true
boolean pauseOnFling = true; // or false
PauseOnScrollListener listener = new PauseOnScrollListener(imageLoader, pauseOnScroll, pauseOnFling);
listView.setOnScrollListener(listener);

Android dynamic background change

I am relatively new to Android platform so I don't know if there exists some specific way for doing this. Here goes my problem
I have a layout with a background image. On that background image I have 2 text views (one for header and other for sub header). Also I have four other image view for 4 very small images and 2 button. Now after fixed time interval (say 4 seconds ) I want all the background image, other 4 images and two text to change dynamically. Only the layout of buttons remains constant.
Rest all change after some time. Now this change should keep on happening.
Basically I need to show 4 screens. When user launch app , user see 1st screen then it changes to 2 screen then 3rd then 4th and then back to 1 and so on. I am currently using Animation.Drawable individually for background image and other four images. But i am unable to change text and the transition b/w images is not very smooth.
Is there a way by which i can solve this problem?
Here is my xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/login_page"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbarAlwaysDrawVerticalTrack="true"
tools:context=".MainActivity" >
<ImageView
android:id="#+id/background_image"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:contentDescription="TODO"
android:scaleType="fitXY"
/>
<ImageView
android:id="#+id/dot_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/signin"
android:layout_marginLeft="264dp"
android:contentDescription="TODO"
/>
<ImageView
android:id="#+id/dot_image2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/signin"
android:layout_marginLeft="284dp"
android:contentDescription="TODO"
android:src="#drawable/introdot_inactive" />
<ImageView
android:id="#+id/dot_image3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/signin"
android:layout_marginLeft="304dp"
android:contentDescription="TODO"
android:src="#drawable/introdot_inactive" />
<ImageView
android:id="#+id/dot_image4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/signin"
android:layout_marginLeft="324dp"
android:contentDescription="TODO"
android:src="#drawable/introdot_inactive" />
<com.facebook.widget.LoginButton
android:id="#+id/facebook_signin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginBottom="120dp"
android:layout_marginRight="43dp"
/>
<Button
android:id="#+id/signin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/facebook_signin"
android:layout_alignLeft="#+id/SubHeaderText"
android:layout_alignParentBottom="true"
android:layout_alignTop="#+id/facebook_signin"
android:layout_marginBottom="120dp"
android:background="#BBBBBB"
android:fitsSystemWindows="true"
/>
<TextView
android:id="#+id/HeaderText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/signin"
android:layout_alignParentTop="true"
android:layout_marginTop="42dp"
android:text="Welcome"
android:textColor="#666666"
android:textSize="23pt"
android:typeface="serif" />
<TextView
android:id="#+id/SubHeaderText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="44dp"
android:layout_marginTop="152dp"
android:text="Subheader text"
android:textColor="#666666"
android:textSize="15pt"
android:typeface="serif" />
</RelativeLayout>
You can change it setting the layout background resource in a UI thread or you can use framelayout. For frame layout you need to design an animation which is on the back and other components on the front.
Check this.

Categories

Resources