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);
Related
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.
I m developping webrtc android application, I used Relative layout to put in it two SurfaceViewRenderer elements one used for local stream view and other for remote stream.
here my layout xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="0dip"
android:layout_weight="0"
android:layout_width="match_parent"
android:id="#+id/video_layout"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical"
android:clickable="true"
android:focusable="false"
>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/glview_parent"
>
<org.webrtc.SurfaceViewRenderer
android:id="#+id/remoteview"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_above="#+id/localview"
/>
<org.webrtc.SurfaceViewRenderer
android:id="#+id/localview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
<TextView
android:id="#+id/messageTXT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:paddingTop="50dp"
android:paddingRight="50dp"
android:padding="10dp"
android:textSize="20sp"
android:background="#66000000"
android:textColor="#color/list_background"
android:visibility="gone"
/>
<Chronometer
android:id="#+id/chronoLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:paddingTop="50dp"
android:paddingRight="50dp"
android:padding="10dp"
android:textSize="20sp"
android:background="#66000000"
android:textColor="#color/list_background"
android:visibility="gone"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/buttons_layout"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:padding="5dp"
android:background="#66000000"
>
<ImageButton
android:id="#+id/speaker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/speaker_on"
android:background="#android:color/transparent"
android:paddingRight="10dp"
/>
<ImageView
android:id="#+id/ok01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_ok"
android:background="#android:color/transparent"
android:visibility="gone"
android:paddingRight="10dp"
/>
<ImageView
android:id="#+id/no01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/ic_no"
android:visibility="gone"
android:paddingRight="10dp"
/>
<ImageButton
android:id="#+id/micro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/mico_on"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
on call progressing i initialised local and remote SurfaceViewRenderer programetically like this .
public void initVideos() {
remotevideoview.setVisibility(View.GONE);
RelativeLayout.LayoutParams local,remote;
remote=new RelativeLayout.LayoutParams(0,0);
remotevideoview.setLayoutParams(remote);
local = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
localvideoView.setLayoutParams(local);
}
When call is establiched and onaddstream event fire I update layout like this :
public void updateVideos(){
RelativeLayout.LayoutParams remote = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
int w=video_layout.getWidth();
int h=video_layout.getHeight();
RelativeLayout.LayoutParams local = new RelativeLayout.LayoutParams(w/3, h/3); // or wrap_content
local.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
local.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
local.setMargins(2, 2, 2, 2);
glview_parent.updateViewLayout(remotevideoview, remote);
glview_parent.updateViewLayout(localvideoView, local);
remotevideoview.setVisibility(View.VISIBLE);
localvideoView.bringToFront();
glview_parent.invalidate();
localvideoView.invalidate();
remotevideoview.invalidate();
}
All is ok until now. but when i click onbackpressed and exit call activity. and after that I like to show local and remote videos again when user enter on call activity. I call updateVideos() and i render local and remote stream but I can not see localvideoView. I see only remotevideoview that match all parent width and height. localvideoview is always bring to back . I try all possible codes but I can not see localview. I use localvideoView.bringToFront(); but without success.
While loading image a thin line appears and the image is not visible while using fresco in a RecyclerView on Android Jellybean devices but the same works on KitKat+ devices.
Samsung - 4.1.1 - API 16 - 768 X 1280
SamsungGalaxyNote2 - 4.3 - API 18 - 720 X 1280
NOTE : Have tested in multiple devices and the scenario is the same
This is the way we are using it in the library
if (newsModelStoreList.get(position-1).getImageUrl() != null) {
String imageUrl = newsModelStoreList.get(position-1).getImageUrl();
String extension=".jpg";
try {
extension = imageUrl.substring(imageUrl.lastIndexOf("."));
}
catch (Exception e)
{
}
Log.d("extension: ",extension);
if(extension.equals(".gif")) {
Log.d("Detected Gif: ", "Starting gif controller");
DraweeController controller = Fresco.newDraweeControllerBuilder()
.setUri(Uri.parse(imageUrl))
.setAutoPlayAnimations(true)
.build();
myHolder.newsImage.setController(controller);
}
else
{
myHolder.newsImage.setImageURI(Uri.parse(imageUrl));
}
}
I AM 100% SURE THAT URL IS AVAILABLE AND IS WORKING ON 4.4+ DEVICES
This is the news_layout.xml which gets inflated
<?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="wrap_content"
android:background="#color/feed_bg"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/bg_parent_rounded_corner"
android:layout_marginTop="#dimen/feed_item_margin"
android:orientation="vertical"
android:paddingBottom="#dimen/feed_item_padding_top_bottom"
android:paddingTop="#dimen/feed_item_padding_top_bottom" >
<LinearLayout
android:layout_width="fill_parent"
android:gravity="right"
android:layout_height="wrap_content">
<TextView
android:id="#+id/timestamp"
android:gravity="right"
android:paddingRight="10dp"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="posted 5 min ago"
android:textColor="#color/timestamp"
android:textSize="#dimen/feed_item_timestamp" />
</LinearLayout>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/newsTitle"
android:textSize="22dp"
android:clickable="false"
android:textStyle="bold"
android:paddingLeft="#dimen/feed_item_status_pad_left_right"
android:paddingRight="#dimen/feed_item_status_pad_left_right"
android:textColor="#color/black"
android:textColorLink="#color/com_facebook_blue"
android:layout_marginBottom="5dp"
android:paddingBottom="5dp"
/>
<TextView
android:id="#+id/newsInformation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingBottom="5dp"
android:textColor="#color/black"
android:textColorLink="#color/com_facebook_blue"
android:paddingLeft="#dimen/feed_item_status_pad_left_right"
android:paddingRight="#dimen/feed_item_status_pad_left_right"
android:paddingTop="#dimen/feed_item_status_pad_top" >
</TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/viewMore" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_gravity="right"
android:layout_height="wrap_content">
</LinearLayout>
SimpleDraweeView is used here ...
<com.facebook.drawee.view.SimpleDraweeView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:visibility="visible"
android:adjustViewBounds="true"
android:id="#+id/newsImage"/>
The rest of the xml is just for reference just in case it would help
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/pad_5dp">
<TextView
android:id="#+id/awesomeness"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#color/timestamp"
android:text="Awesomeness: "
android:textSize="#dimen/feed_item_timestamp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/awesomenessCountNumber"
android:text="0"
android:textColor="#color/timestamp"
android:textSize="#dimen/feed_item_timestamp"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingTop="#dimen/pad_5dp"
android:layout_marginLeft="#dimen/pad_5dp"
android:layout_marginRight="#dimen/pad_5dp">
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/awesomeButton"
android:layout_marginRight="8dp"
android:background="#drawable/awesome_button_2"/>
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/facebookSharePost"
android:layout_marginRight="8dp"
android:background="#drawable/facebook_icon"
/>
<Button
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/whatsApp"
android:background="#drawable/whats_app_icon"/>
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1"
/>
<TextView
android:layout_marginRight="8dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Report"/>
<Button
android:layout_marginRight="6dp"
android:layout_width="30dp"
android:layout_height="30dp"
android:id="#+id/report"
android:background="#drawable/report_empty" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
Guesses as to what you are doing wrong:
You are using wrap_content. Fresco does not support this unless you also supply a fresco:viewAspectRatio. See the guide to Drawees and the longer explanation about wrap_content.
You are using android:scaleType. This has no effect on SimpleDraweeViews. You need to use fresco:actualImageScaleType. Also be sure that fitXY is really what you want; this does not preserve the aspect ratio. See the documentation on scale types.
Here is what I'm trying to do. I have 4 images and they are in one LinearLayout and that LinearLayout is child of RelativeLayout. I have successfully implemented onClickListener. Maybe my question is a little different, but everything is relevant.
I don't know how to extend image to full screen because images are in one LinearLayout which is inside that one RelativeLayout and maybe everything will be clear when I show you guys xml code.
I would like to make ImageView full screen on click and to be able to go back when I click back button. For that I would probably need to use onBackPressed
Images are at the bottom.
So here is the xml code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:background="#drawable/url"
android:fillViewport="true"
android:orientation="vertical"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:scrollbars="none" >
<RelativeLayout
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<!-- Thumbnail Image -->
<com.dusandimitrijevic.modification.TouchImageView
android:id="#+id/thumbnail"
android:layout_width="140dp"
android:layout_height="220dp"
android:layout_alignParentLeft="true"
android:layout_marginRight="8dp"
android:src="#drawable/ic_horor_filmovi_ikonica" />
<!-- Naslov Filma -->
<TextView
android:id="#+id/naslov"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#7F0000"
android:textSize="#dimen/title_movie"
android:layout_toRightOf="#id/thumbnail"
android:layout_toEndOf="#+id/thumbnail" >
</TextView>
<!-- Godina izdanja Filma -->
<TextView
android:id="#+id/releaseYear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/naslov"
android:layout_alignStart="#+id/naslov"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_below="#+id/naslov"
android:layout_marginTop="3dp"
android:textColor="#color/dark_red" />
<ImageView
android:id="#+id/rating_star"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/thumbnail"
android:layout_marginBottom="42dp"
android:layout_toRightOf="#+id/thumbnail"
android:layout_toEndOf="#+id/thumbnail"
android:src="#drawable/ic_actions_rating_icon" />
<Button
android:id="#+id/url_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/thumbnail"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="#+id/thumbnail"
android:layout_toEndOf="#+id/thumbnail"
style="#style/UrlDugme" />
<TextView
android:id="#+id/rating"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/rating_star"
android:layout_alignTop="#+id/rating_star"
android:layout_toRightOf="#+id/rating_star"
android:layout_toEndOf="#+id/rating_star"
android:gravity="center"
android:textColor="#color/dark_red"
android:textSize="#dimen/rating" />
<!-- Opis Filma -->
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_below="#+id/thumbnail"
android:layout_marginTop="14dp"
android:background="#drawable/layout_round_rect_shape" >
<TextView
android:id="#+id/description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="16dp"
android:scrollbars="vertical"
android:textColor="#color/dark_red"
android:textSize="18sp" />
</RelativeLayout>
<!-- Opis Filma Zavrsetak -->
<!-- Glumci -->
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/relativeLayout1"
android:layout_marginTop="12dp"
android:background="#drawable/layout_round_rect_shape"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/linearLayoutActors"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/Image1"
android:layout_width="40dp"
android:layout_height="140dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_horor_filmovi_ikonica" />
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/Image2"
android:layout_width="40dp"
android:layout_height="140dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_horor_filmovi_ikonica" />
<com.android.volley.toolbox.NetworkImageView
android:id="#+id/Image3"
android:layout_width="40dp"
android:layout_height="140dp"
android:layout_gravity="center_horizontal"
android:layout_marginTop="16dp"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="#drawable/ic_horor_filmovi_ikonica" />
</LinearLayout>
<LinearLayout
android:id="#+id/linearLayoutTextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayoutActors"
android:orientation="horizontal" >
<TextView
android:id="#+id/ime1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Ime"
android:textColor="#7F0000"
android:textSize="16sp" />
<TextView
android:id="#+id/ime2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Ime"
android:textColor="#7F0000"
android:textSize="16sp" />
<TextView
android:id="#+id/ime3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Ime"
android:textColor="#7F0000"
android:textSize="16sp" />
</LinearLayout>
</RelativeLayout>
<!-- Glumci -->
<!-- IMAGES I WANT TO MAKE FULLSCREEN ON CLICK -->
<LinearLayout
android:layout_marginTop="12dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#drawable/layout_round_rect_shape"
android:id="#+id/linearLayoutImages"
android:layout_below="#+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<com.dusandimitrijevic.modification.TouchImageView
android:id="#+id/image1"
android:adjustViewBounds="true"
android:layout_weight="1"
android:layout_width="115dp"
android:layout_height="150dp"
android:src="#drawable/ic_horor_filmovi_ikonica" >
</com.dusandimitrijevic.modification.TouchImageView>
<com.dusandimitrijevic.modification.TouchImageView
android:id="#+id/image2"
android:adjustViewBounds="true"
android:layout_weight="1"
android:layout_width="115dp"
android:layout_height="150dp"
android:src="#drawable/ic_horor_filmovi_ikonica" >
</com.dusandimitrijevic.modification.TouchImageView>
<com.dusandimitrijevic.modification.TouchImageView
android:id="#+id/image3"
android:adjustViewBounds="true"
android:layout_weight="1"
android:layout_width="115dp"
android:layout_height="150dp"
android:src="#drawable/ic_horor_filmovi_ikonica" >
</com.dusandimitrijevic.modification.TouchImageView>
<com.dusandimitrijevic.modification.TouchImageView
android:id="#+id/image4"
android:adjustViewBounds="true"
android:layout_weight="1"
android:layout_width="115dp"
android:layout_height="150dp"
android:src="#drawable/ic_horor_filmovi_ikonica" >
</com.dusandimitrijevic.modification.TouchImageView>
</LinearLayout>
<!-- IMAGES I WANT TO MAKE FULLSCREEN ON CLICK -->
</RelativeLayout>
</ScrollView>
</RelativeLayout>
And here is onClickListener:
image1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int px = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 115, getResources().getDisplayMetrics());
int px1 = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_SP, 150, getResources().getDisplayMetrics());
LinearLayout.LayoutParams p = new LinearLayout.
LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
p.weight = 1;
if(isImageFitToScreen) {
image1.setMinimumWidth(px);
image1.setMinimumHeight(px1);
image1.setAdjustViewBounds(true);
isImageFitToScreen=false;
}else{
image1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
image1.setScaleType(ImageView.ScaleType.FIT_XY);
isImageFitToScreen=true;
}
}
});
To offer an alternative to Ben's answer and flesh out my earlier comment, one possibility is to create an ImageView in your xml that occupies the entire screen, with its visibility set to gone. On your button press, load the image into this ImageView, and on a back press set the visibility to gone again.
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
xmlns:android="http://schemas.android.com/apk/res/android"
>
<ScrollView>
<!-- Everything else! -->
</ScrollView>
<ImageView
android:id="#+id/full_screen_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="gone" />
</RelativeLayout>
Inside your Activity's onCreate() method:
#Override
public void onCreate(Bundle mySavedInstances) {
ImageView fullScreenContainer = (ImageView) findViewById(R.id.full_screen_container);
image1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
//However it is you load your images
fullScreenContainer.setImageDrawawble(R.drawable.example);
fullScreenContainer.setVisibility(View.VISIBLE);
}
});
}
#Override
public void onBackPressed() {
if (fullScreenContainer.getVisibility() == View.VISIBLE) {
fullScreenContainer.setImageDrawable(null);
fullScreenContainer.setVisibility(View.GONE);
} else {
super.onBackPressed();
}
}
Welcome to stack overflow Dusan,
I've something very similar, but all I do is just put the full screen image in a new activity & pass the image as bytes & display it in a full screened imageview. As soon as they press back, they're returned to where they were before. I think trying to change the layout parameters is a bit overkill here.
Create new Activity or Fragment and set image to ImageView in new Activity or Fragment. Using Fragment is better approach here as user can click on multiple images one after another. It is less expensive to create or destory Fragment.
Image can be passed to another activity by converting into byte array. It is better approach to save image on server or database such as firebase etc and use generated URL in app. Which make it easy to pass Url between Activities or Fragments than passing byte array
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.