How to set popup window style for responsive UI in android - android

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

Related

Cannot get Button location in Android App

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.

Android View Not Comming as LayOut I design?

I beginner of Android development , I created sample view using Android studio.but when i run not give proper out put.please , refer following image.
I create my Home page LayOut as Right Picture.But when I run Come View Like Left Hand Picture.I run different Emulators but out put is same. Please ,hope some expert help .
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="0.17">
<ImageButton
android:layout_width="136dp"
android:layout_height="wrap_content"
android:id="#+id/imageButtonService"
android:layout_gravity="center_horizontal"
android:layout_weight="0.17"
android:src="#drawable/services"
android:background="#null"
android:layout_marginBottom="36dp"
android:layout_above="#+id/imageButtontransaction"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="25dp"
android:layout_marginStart="25dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Service"
android:id="#+id/textView"
android:layout_alignTop="#+id/tvProfile"
android:layout_alignRight="#+id/imageButtonService"
android:layout_alignEnd="#+id/imageButtonService"
android:layout_marginRight="24dp"
android:layout_marginEnd="24dp" />
<ImageButton
android:layout_width="136dp"
android:layout_height="wrap_content"
android:id="#+id/imageButtonProfile"
android:layout_gravity="center_horizontal"
android:layout_weight="0.17"
android:src="#drawable/profile"
android:background="#null"
android:layout_alignTop="#+id/imageButtonService"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="58dp"
android:layout_marginEnd="58dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Profile"
android:id="#+id/tvProfile"
android:layout_alignBottom="#+id/imageButtonService"
android:layout_alignRight="#+id/imageButtonProfile"
android:layout_alignEnd="#+id/imageButtonProfile"
android:layout_marginRight="26dp"
android:layout_marginEnd="26dp" />
<ImageButton
android:layout_width="136dp"
android:layout_height="wrap_content"
android:id="#+id/imageButtontransaction"
android:layout_gravity="center_horizontal"
android:layout_weight="0.17"
android:src="#drawable/transaction"
android:background="#null"
android:layout_alignTop="#+id/imageButtonwallet"
android:layout_alignRight="#+id/tvTransaction"
android:layout_alignEnd="#+id/tvTransaction" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Transaction"
android:id="#+id/tvTransaction"
android:layout_marginBottom="97dp"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/imageButtonService"
android:layout_alignEnd="#+id/imageButtonService" />
<ImageButton
android:layout_width="136dp"
android:layout_height="wrap_content"
android:id="#+id/imageButtonwallet"
android:layout_gravity="center_horizontal"
android:layout_weight="0.17"
android:src="#drawable/wallet"
android:background="#null"
android:layout_above="#+id/tvWallet"
android:layout_alignRight="#+id/imageButtonProfile" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Wallet"
android:id="#+id/tvWallet"
android:layout_alignTop="#+id/tvTransaction"
android:layout_alignLeft="#+id/tvProfile"
android:layout_alignStart="#+id/tvProfile" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Welcome SCPP Home"
android:id="#+id/tvWelcom"
android:layout_above="#+id/imageButtonService"
android:layout_alignRight="#+id/tvProfile"
android:layout_alignEnd="#+id/tvProfile"
android:layout_marginBottom="36dp" />
</RelativeLayout>
</LinearLayout>
My Activity Class.
public class Home extends Activity implements View.OnClickListener{
private final int SPLASH_DISPLAY_LENGTH = 2000;
private ImageButton profileimgButton;
private ImageButton transctionimgButton;
private ImageButton walletimgButton;
private ImageButton serviceimgButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
initUi();
}
private void initUi() {
profileimgButton = (ImageButton) findViewById(R.id.imageButtonProfile);
transctionimgButton=(ImageButton) findViewById(R.id.imageButtontransaction);
walletimgButton=(ImageButton) findViewById(R.id.imageButtonwallet);
serviceimgButton=(ImageButton) findViewById(R.id.imageButtonService);
profileimgButton.setOnClickListener(Home.this);
transctionimgButton.setOnClickListener(Home.this);
walletimgButton.setOnClickListener(Home.this);
serviceimgButton.setOnClickListener(Home.this);
}
}

How to make ImageView fullscreen programmatically on click?

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

setVisibility(view.GONE) is not working Android

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.

Why is my relative layout filling the screen rather than wrapping content when I add an image?

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

Categories

Resources