I am trying to get the absolute location of my buttons after they have been drawn into view by the RelativeLayout. This is so that I can draw a pulsing glow animation at the location of the buttons. I have tried Button.getX(); and Button.getLocationOnScreen(); and both have returned an integer value of 0. I tried putting the buttons into a LinearLayout and was still unable to get coordinates for the button location on screen. I also tried running onPostCreate() to ensure the buttons were on screen before checking their location. I want to get their location on application boot, so theat I can create an animation to run underneath them. It seems that Button locations cannot be determined during onCreate. Anything I might be missing?
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final Button playButton = findViewById(R.id.play);
System.out.println(playButton.getX());
playButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
play();
}
});
playButton.getX();
playButton.getY();
*OR*
int playLoc = int[2] //<--- create two dimensional array for x and y
playLoc = playButton.getLocationOnScreen();
and The XML Layout file:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/background"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/black"
android:orientation="vertical"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#000000"
android:theme="#style/AppTheme.AppBarOverlay">
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:elevation="4dp"
android:theme="#style/ThemeOverlay.AppCompat.ActionBar"
app:popupTheme="#style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.AppBarLayout>
<!--<com.example.macyg.androidmediaplayer.CustomView
android:layout_width="wrap_content"
android:layout_height="140dp"
android:layout_alignParentBottom="true"
android:background="#000000"/>-->
<android.support.v7.widget.AppCompatSeekBar
android:id="#+id/seekbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_gravity="bottom"
android:layout_marginBottom="20dp" />
<android.support.v7.widget.AppCompatButton
android:id="#+id/play"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_above="#id/seekbar"
android:layout_centerHorizontal="true"
android:layout_gravity="center"
android:background="#android:drawable/ic_media_play" />
<android.support.v7.widget.AppCompatButton
android:id="#+id/forward"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_above="#id/seekbar"
android:layout_gravity="end"
android:layout_toEndOf="#id/play"
android:background="#android:drawable/ic_media_next" />
<android.support.v7.widget.AppCompatButton
android:id="#+id/backward"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_above="#id/seekbar"
android:layout_toStartOf="#id/play"
android:background="#android:drawable/ic_media_previous"
android:shadowColor="#color/white"
android:shadowRadius="50" />
<android.support.v7.widget.AppCompatButton
android:id="#+id/aButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_above="#+id/seekbar"
android:layout_alignStart="#id/backward"
android:layout_alignParentStart="true"
android:layout_marginTop="?attr/actionBarSize"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:fontFamily="sans-serif"
android:text="A" />
<android.support.v7.widget.AppCompatButton
android:id="#+id/bButton"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_above="#+id/seekbar"
android:layout_toRightOf="#id/aButton"
android:layout_alignParentRight="false"
android:layout_marginBottom="5dp"
android:fontFamily="sans-serif"
android:text="B" />
<ImageView
android:id="#+id/album_art"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_alignParentEnd="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="?attr/actionBarSize"
android:layout_marginEnd="3dp"
android:background="#android:color/darker_gray"
android:visibility="invisible" />
<TextView
android:id="#+id/currTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginLeft="5dp"
android:layout_marginBottom="5dp"
android:fontFamily="sans-serif"
android:text="#string/default_time"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/trackLength"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:layout_marginRight="5dp"
android:layout_marginBottom="5dp"
android:fontFamily="sans-serif"
android:text="#string/default_time"
android:textColor="#android:color/white"
android:textSize="12sp" />
<TextView
android:id="#+id/album_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/artist_name"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif"
android:singleLine="true"
android:textColor="#ffffff"
android:textSize="18sp" />
<TextView
android:id="#+id/songName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/album_art"
android:layout_alignParentRight="true"
android:fontFamily="sans-serif"
android:singleLine="true"
android:textColor="#ffffff"
android:textSize="18sp" />
<TextView
android:id="#+id/artist_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/songName"
android:layout_alignParentRight="true"
android:layout_marginTop="0dp"
android:fontFamily="sans-serif"
android:singleLine="true"
android:textColor="#ffffff"
android:textSize="18sp" />
I found an answer to my problem. Rather than use the onPostCreate() method I use a post method (which is a function of the Button class) inside the onCreate() method to state that AFTER the button has been drawn into view by the relative layout so that I can get the locations of the buttons after they have been drawn in view. This is useful for when you run the application on devices with different screen sizes you will always know the coordinates of where the button was drawn.
How get Button coordinate?
I hope this saves people the amount of time I spent trying to solve this! and thank you to Vektor88 for the solution!
Also here is the code in the onCreate setup phase. This worked correctly for me:
playButton = findViewById(R.id.play);
playButton.post(new Runnable() {
#Override
public void run() {
playx = playButton.getX();
playy = playButton.getY();
System.out.println("play x = " + playx + " play y = " + playy);
}
});
NOTE
Why am I getting negative ratings on this post? I felt I gave very clear posts leading up to the answer and I don't feel I should have been answer banned.
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.
In My android app, I used popup window.
There is one issue regarding popup window.
In bigger device (height or width) It will show clearly and automatically set margin left or right.
In smaller device like nexus one , Popup window stick with device not set margin left or right.
Or another issue is that In lollipop or marshmallow there is one button look like floating button. You can view in screen shot which I attached below.
That button look good in marshmallow or higher version.
But in kitkat there is only look like a simple arrow how to resolved it.
Here i specified My popup window source code or screenshots of kitkat device UI and Marshmallow UI.
please any one let me know how to resolved it. In advance, Thank you for your support.
raw_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/demo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/colorWhite"
android:orientation="horizontal"
android:padding="16dp">
<TextView
android:id="#+id/txtMainHeading"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp"
android:layout_marginLeft="10dp"
android:text="#string/headertext"
android:textColor="#color/colorBlack"
android:textSize="16sp"
android:textStyle="bold" />
<TextView
android:id="#+id/txtText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:padding="10dp"
android:text="#string/popupsubtext"
android:textColor="#color/colorBlack" />
<View
android:id="#+id/viewMain"
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_below="#+id/txtText"
android:background="#color/bg_border" />
<View
android:id="#+id/view"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="#+id/LayoutDetail"
android:layout_marginLeft="95dp"
android:layout_marginRight="10dp"
android:background="#color/bg_border" />
<LinearLayout
android:id="#+id/LayoutDetail1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/view"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txtLastNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="#string/puplastname"
android:textColor="#color/colorBlack"
android:textSize="15sp" />
<TextView
android:id="#+id/txtLastName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:focusableInTouchMode="true"
android:text="#string/txtLastnametext"
android:textColor="#color/button_text_dialog"
android:textSize="16sp" />
</LinearLayout>
<View
android:id="#+id/view1"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="#+id/LayoutDetail1"
android:layout_marginLeft="95dp"
android:layout_marginRight="10dp"
android:background="#color/bg_border" />
<LinearLayout
android:id="#+id/LayoutDetail2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/view1"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txtEmailText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="#string/pupEmail"
android:textColor="#color/colorBlack"
android:textSize="15sp" />
<TextView
android:id="#+id/txtEmail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="#string/txtemailtext"
android:textColor="#color/button_text_dialog"
android:textSize="16sp" />
</LinearLayout>
<View
android:id="#+id/view2"
android:layout_width="wrap_content"
android:layout_height="2dp"
android:layout_below="#+id/LayoutDetail2"
android:layout_marginBottom="10dp"
android:layout_marginLeft="70dp"
android:layout_marginRight="10dp"
android:background="#color/bg_border" />
<ImageView
android:id="#+id/btnNext"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/LayoutDetail2"
android:layout_margin="#dimen/fab_margin"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="14dp"
android:background="#drawable/shape_oval"
android:elevation="2dp"
android:scaleType="center"
android:src="#drawable/ic_icon_right_1" />
<LinearLayout
android:id="#+id/LayoutDetail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/txtText"
android:layout_gravity="center"
android:orientation="horizontal">
<TextView
android:id="#+id/txtFirstNameText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:text="#string/pupfirstname"
android:textColor="#color/colorBlack"
android:textSize="15sp" />
<TextView
android:id="#+id/txtFirstName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:focusableInTouchMode="true"
android:text="#string/txtFirstnametext"
android:textColor="#color/button_text_dialog"
android:textSize="16sp" />
</LinearLayout>
Popupwindow.java
private Context mContext;
private Activity mActivity;
private android.widget.PopupWindow mPopupWindow;
private RelativeLayout mRelativeLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_countrycode);
mContext = getApplicationContext();
// Get the activity
mActivity = CountrycodeActivity.this;
// Get the widgets reference from XML layout
mRelativeLayout = (RelativeLayout) findViewById(R.id.mRelativeLayout);
LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(LAYOUT_INFLATER_SERVICE);
// Inflate the custom layout/view
View customView = inflater.inflate(R.layout.raw_layout, null);
mPopupWindow = new android.widget.PopupWindow(
customView,
ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT
);
// mPopupWindow.setContentView(findViewById(R.id.activity_view_pager));
mPopupWindow.setAnimationStyle(R.style.PopupAnimation);
if (Build.VERSION.SDK_INT >= 21) {
mPopupWindow.setElevation(24f);
}
new Handler().postDelayed(new Runnable() {
public void run() {
mPopupWindow.showAtLocation(mRelativeLayout, Gravity.CENTER, 0, 0);
}
}, 100L);
}
#Override
protected void onStop() {
super.onStop();
mPopupWindow.dismiss();
}
Screenshots of UI
In marshmallow as well as bigger device nexus 5.1
In nexus one as well as kitkat device or smaller
android:layout_width="fill_parent"
set RelativeLayout width property fill_parent
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 need to disable the view programmatically so i used setVisibility(view.GONE) in activity. My xml have two buttons named lower and upper and two relative layouts named lower_lay and upper_lay.when i click the lower button i need enable lower_lay and i click the upper button i need to enable upper_lay. Both in upeer_lay and lower_lay having images and performing onTouch event. Now my problem is when i am in lower_lay the images of upper_lay are disabled but when i touch the empty space in lower_lay, upper_lay images are coming...and in upper_lay i am having this issue. Why the view is not completelt gone?
i am trying this from 3 days....please any one help me out.
xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/r1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
>
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1e356a">
<TextView
android:id="#+id/placce_head"
android:layout_width="wrap_content"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:text="Hyderabad to banglore"
android:textColor="#ffffff"
android:textSize="20dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:id="#+id/seats"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Selected Seats"
android:textColor="#ffffff"
android:textSize="16dp" />
<TextView
android:id="#+id/totalamount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="Total Amount"
android:textColor="#ffffff"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#78869c"
android:weightSum="2"
android:orientation="horizontal">
<TextView
android:id="#+id/seat_num"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:textColor="#ffffff"
android:textSize="16dp" />
<TextView
android:id="#+id/total_amount"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginLeft="10dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:textColor="#ffffff"
android:textSize="16dp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#1e356a"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#1e356a"
android:layout_marginTop="5dp"
android:layout_marginBottom="10dp"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:src="#drawable/bluesmall"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:text="Available"
android:textSize="12dp"
android:textColor="#ffffff"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:src="#drawable/greensmall"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:textSize="12dp"
android:textColor="#ffffff"
android:text="Selected"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:src="#drawable/pinksmall"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ladies"
android:textSize="12dp"
android:textColor="#ffffff"
android:layout_marginLeft="6dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:src="#drawable/redsmall"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="6dp"
android:textSize="12dp"
android:textColor="#ffffff"
android:text="Booked"/>
</LinearLayout>
<LinearLayout
android:id="#+id/sleeper_lay"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#78869c"
android:weightSum="2"
android:padding="7dp"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
>
<Button
android:id="#+id/lower"
android:layout_width="0dp"
android:layout_weight="1"
android:text="Lower"
android:textColor="#F93249"
android:gravity="center"
android:textSize="18dp"
android:layout_height="wrap_content" />
<Button
android:id="#+id/upper"
android:layout_width="0dp"
android:layout_weight="1"
android:text="Upper"
android:textSize="18dp"
android:textColor="#ffffff"
android:gravity="center"
android:layout_height="wrap_content" />
</LinearLayout>
<RelativeLayout
android:id="#+id/relative_layout"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/bg_border"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
</RelativeLayout>
<RelativeLayout
android:id="#+id/relative_layout_two"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/bg_border"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center" >
</RelativeLayout>
<Button
android:id="#+id/done_btn"
android:background="#F93249"
android:textColor="#ffffff"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="done"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</RelativeLayout>
Activitiy:
lower_lay = (RelativeLayout) findViewById(R.id.relative_layout);//lower layout
upper_lay= (RelativeLayout) findViewById(R.id.relative_layout_two);//upperlayout
upper.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
lower_lay.setVisibility(View.GONE);
upper.setTextColor(Color.parseColor("#F93249"));
lower.setTextColor(Color.parseColor("#ffffff"));
upper_lay.setVisibility(View.VISIBLE);
sheetdetails.clear();
}
});
lower.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View view) {
upper_lay.setVisibility(View.GONE);
upper.setTextColor(Color.parseColor("#ffffff"));
lower.setTextColor(Color.parseColor("#F93249"));
lower_lay.setVisibility(View.VISIBLE);
}
});
Try using
View.GONE
not
view.GONE
and lower.setOnClickListener not lower.setOnTouchListener
View is the class, so should starts with capital letter.
Kindly see my updates.
upper.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
lower_lay.setVisibility(View.GONE);
upper.setTextColor(Color.parseColor("#F93249"));
lower.setTextColor(Color.parseColor("#ffffff"));
upper_lay.setVisibility(View.VISIBLE);
}
});
lower.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
lower_lay.setVisibility(View.VISIBLE);
upper.setTextColor(Color.parseColor("#ffffff"));
lower.setTextColor(Color.parseColor("#F93249"));
upper_lay.setVisibility(View.GONE);
}
});
I will give you a good advice about your layout:
From Chat Haase blog:
RelativeLayout is a very convenient layout to use, because it allows
developers to specify how content should be placed relative to other
content. In many situations, this is necessary and may be the best
solution for the job. However, it is important to understand that
RelativeLayout is an expensive solution, because it requires two
measurement passes to ensure that it has handled all of the layout
relationships correctly. Moreover, this problem compounds with every
additional RelativeLayout throughout the hierarchy. Imagine a
RelativeLayout at the top of your view hierarchy; this essentially
doubles the measurement work on your entire view hierarchy. Now
imagine another RelativeLayout as one of the children of that first
one — this doubles again the measurement passes that happen under it,
requiring four measurement passes for all of the views in its
sub-hierarchy.
Use a different type of layout for situations that do not require the
capabilities of RelativeLayout, such as LinearLayout or even a custom
layout. Or for situations in which relative alignment of child views
is necessary, consider the more optimized GridLayout, which
pre-processes the child view relationships and avoids the
double-measurement problem.
I have a RelativeLayout, we'll call this the 'slider', that I want to overlay on another RelativeLayout (by switching visibility="gone" and "visible") when "Add People" is clicked, but the overlay should only take up as much width of the screen as needed. This layout will then be removed when "Cancel" is clicked. Everything is working fine so far.
RelativeLayout slider;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_people);
RelativeLayout add = (RelativeLayout) findViewById(R.id.add_wrapper);
RelativeLayout cancel = (RelativeLayout) findViewById(R.id.cancel_wrapper);
slider = (RelativeLayout) findViewById(R.id.add_people_slider);
add.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
slider.setVisibility(View.VISIBLE);
}
});
cancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
slider.setVisibility(View.GONE);
}
});
}
The issue arises when I try to add another image to the slider. I am adding this just above the #id/cancel_wrapper RelativeLayout in the XML (full XML at bottom).
<ImageView
android:id="#+id/transparent_add"
android:src="#drawable/ic_add_active_256"
android:layout_height="30dp"
android:layout_width="30dp"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true" />
For some reason, this is making the width of the slider the full width of the screen.
What's even more bizarre is if I add android:layout_marginRight="50dp" to this ImageView to move it left a little it starts making the slider smaller from the left. I would like this "transparent_add" image to be lined up with the old "add" image.
My 2 issues, then, are that when I add the "transparent_add" image it changes the width of the slider for an unknown reason, and also when I add marginRight on the image it makes the width of the slider smaller from the left.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#color/white" >
<TextView
android:id="#+id/btn_people"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingLeft="10dp"
android:text="#string/label_people"
android:textColor="#color/blue"
android:textSize="16dp" />
<TextView
android:id="#+id/people_info"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/btn_people"
android:paddingLeft="10dp"
android:text="#string/label_people_info"
android:textSize="11dp" />
<RelativeLayout
android:id="#+id/add_wrapper"
android:layout_width="65dp"
android:layout_height="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:background="#color/blue" >
<ImageView
android:id="#+id/plus_sign"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="19dp"
android:layout_marginTop="6dp"
android:src="#drawable/ic_add_256" />
<TextView
android:id="#+id/add_people"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingBottom="2dp"
android:text="#string/label_add_people"
android:textColor="#color/white"
android:textSize="11dp" />
</RelativeLayout>
<ListView
android:id="#+id/contacts_list"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_below="#id/people_info" />
<!-- switch between visible/gone -->
<RelativeLayout
android:id="#+id/add_people_slider"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:background="#color/blue"
android:visibility="gone" >
<TextView
android:id="#+id/label_add_new_contact"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="65dp"
android:layout_alignParentTop="true"
android:paddingLeft="10dp"
android:paddingRight="15dp"
android:text="#string/label_add_new_contact"
android:textColor="#color/white"
android:textSize="16dp" />
<TextView
android:id="#+id/label_add_from_phone"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/label_add_new_contact"
android:paddingLeft="10dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:text="#string/label_add_from_phone"
android:textColor="#color/white"
android:textSize="16dp" />
<TextView
android:id="#+id/label_add_from_facebook"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/label_add_from_phone"
android:paddingLeft="10dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:text="#string/label_add_from_facebook"
android:textColor="#color/white"
android:textSize="16dp" />
<TextView
android:id="#+id/label_add_from_linkedin"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/label_add_from_facebook"
android:paddingLeft="10dp"
android:paddingRight="15dp"
android:paddingTop="15dp"
android:text="#string/label_add_from_linkedin"
android:textColor="#color/white"
android:textSize="16dp" />
<!-- insert image here -->
<RelativeLayout
android:id="#+id/cancel_wrapper"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:paddingLeft="15dp"
android:paddingRight="15dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:paddingBottom="10dp" >
<ImageView
android:id="#+id/image_cancel"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="4dp"
android:src="#drawable/ic_close_256"/>
<TextView
android:id="#+id/label_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="#string/label_cancel"
android:textColor="#color/white"
android:textSize="8dp" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
EDIT: This is happening both in Eclipse and on my Android device.
EDIT: I have tried placing the image above the "Add a new contact" text and then placing the text below that, but the same thing happens