Having some trouble figuring out why my ImageView buttons stop working after I change the displayed layout in my app. Please tell me if you see anything wrong with this code... The buttons are not clickable after changing setContentView is called even though it is setting the layout to the same one that is originally set in OnCreate. Basically I want to be able to reset the view to an known state whenever I want by calling this function.
Thanks for any ideas! Here is the code that breaks the buttons, really only the line that calls setContentView breaks the buttons, but here is the rest of the function as well:
public void defaultrailview(){
setContentView(R.layout.railtrick);
ImageView jumpsbutton = (ImageView) findViewById(R.id.jumpsbutton);
ImageView settingsbutton = (ImageView) findViewById(R.id.settingsbutton);
jumpsbutton.setClickable(true);
settingsbutton.setClickable(true);
ImageView ghost1 = (ImageView)findViewById(R.id.rt1);
ghost1.setAlpha(51);
ImageView ghost2 = (ImageView)findViewById(R.id.rt2);
ghost2.setAlpha(51);
ImageView ghost3 = (ImageView)findViewById(R.id.rt3);
ghost3.setAlpha(51);
ImageView ghost4 = (ImageView)findViewById(R.id.rt4);
ghost4.setAlpha(51);
ImageView railtext = (ImageView)findViewById(R.id.railstext);
railtext.setAlpha(127);
ImageView shaketoroll = (ImageView)findViewById(R.id.ShakeToRoll);
shaketoroll.setVisibility(4);
}
and the XML for the railtrick:
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/title"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/railstext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:paddingLeft="20dp"
android:src="#drawable/railstext" />
</LinearLayout>
<LinearLayout
android:id="#+id/alldice"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".5"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/dicerow1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<ImageView
android:id="#+id/rt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:adjustViewBounds="true"
android:paddingLeft="10dp"
android:src="#drawable/diceghost"/>
<ImageView
android:id="#+id/rt2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:adjustViewBounds="true"
android:paddingRight="10dp"
android:src="#drawable/diceghost"/>
</LinearLayout>
<LinearLayout
android:id="#+id/dicerow2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<ImageView
android:id="#+id/rt3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:paddingLeft="10dp"
android:src="#drawable/diceghost"/>
<ImageView
android:id="#+id/rt4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="top"
android:layout_marginTop="5dp"
android:layout_weight="1"
android:adjustViewBounds="true"
android:paddingRight="10dp"
android:src="#drawable/diceghost"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/buttons"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1"
android:orientation="horizontal" >
<ImageView
android:id="#+id/jumpsbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:adjustViewBounds="true"
android:clickable="true"
android:paddingLeft="20dp"
android:src="#drawable/jumpsbuttonpassive" />
<ImageView
android:id="#+id/railsbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:adjustViewBounds="true"
android:clickable="true"
android:paddingLeft="5dp"
android:paddingRight="5dp"
android:src="#drawable/railsbuttonactive" />
<ImageView
android:id="#+id/settingsbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="1"
android:adjustViewBounds="true"
android:clickable="true"
android:paddingRight="20dp"
android:src="#drawable/settingsbuttonpassive" />
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/ShakeToRoll"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:adjustViewBounds="true"
android:padding="30dp"
android:src="#drawable/shaketoroll" />
Thanks again. Love you all!
When passing the same value into setContentView, you are still requesting for that resource to be inflated - meaning all new objects.
You need to reassign your onClickListeners because your old buttons are no longer on the screen.
you can try android:onclick="imageButton" in the xml and create a function in your class like
public void imageButton(View view){
// your code
}
Related
I m developping webrtc android application, I used Relative layout to put in it two SurfaceViewRenderer elements one used for local stream view and other for remote stream.
here my layout xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_height="0dip"
android:layout_weight="0"
android:layout_width="match_parent"
android:id="#+id/video_layout"
>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical"
android:clickable="true"
android:focusable="false"
>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:id="#+id/glview_parent"
>
<org.webrtc.SurfaceViewRenderer
android:id="#+id/remoteview"
android:layout_height="0dp"
android:layout_width="0dp"
android:layout_above="#+id/localview"
/>
<org.webrtc.SurfaceViewRenderer
android:id="#+id/localview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</RelativeLayout>
<TextView
android:id="#+id/messageTXT"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:paddingTop="50dp"
android:paddingRight="50dp"
android:padding="10dp"
android:textSize="20sp"
android:background="#66000000"
android:textColor="#color/list_background"
android:visibility="gone"
/>
<Chronometer
android:id="#+id/chronoLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:paddingTop="50dp"
android:paddingRight="50dp"
android:padding="10dp"
android:textSize="20sp"
android:background="#66000000"
android:textColor="#color/list_background"
android:visibility="gone"/>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:id="#+id/buttons_layout"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:layout_marginBottom="10dp"
android:padding="5dp"
android:background="#66000000"
>
<ImageButton
android:id="#+id/speaker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/speaker_on"
android:background="#android:color/transparent"
android:paddingRight="10dp"
/>
<ImageView
android:id="#+id/ok01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_ok"
android:background="#android:color/transparent"
android:visibility="gone"
android:paddingRight="10dp"
/>
<ImageView
android:id="#+id/no01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/ic_no"
android:visibility="gone"
android:paddingRight="10dp"
/>
<ImageButton
android:id="#+id/micro"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:src="#drawable/mico_on"
/>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
on call progressing i initialised local and remote SurfaceViewRenderer programetically like this .
public void initVideos() {
remotevideoview.setVisibility(View.GONE);
RelativeLayout.LayoutParams local,remote;
remote=new RelativeLayout.LayoutParams(0,0);
remotevideoview.setLayoutParams(remote);
local = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
localvideoView.setLayoutParams(local);
}
When call is establiched and onaddstream event fire I update layout like this :
public void updateVideos(){
RelativeLayout.LayoutParams remote = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
int w=video_layout.getWidth();
int h=video_layout.getHeight();
RelativeLayout.LayoutParams local = new RelativeLayout.LayoutParams(w/3, h/3); // or wrap_content
local.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
local.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
local.setMargins(2, 2, 2, 2);
glview_parent.updateViewLayout(remotevideoview, remote);
glview_parent.updateViewLayout(localvideoView, local);
remotevideoview.setVisibility(View.VISIBLE);
localvideoView.bringToFront();
glview_parent.invalidate();
localvideoView.invalidate();
remotevideoview.invalidate();
}
All is ok until now. but when i click onbackpressed and exit call activity. and after that I like to show local and remote videos again when user enter on call activity. I call updateVideos() and i render local and remote stream but I can not see localvideoView. I see only remotevideoview that match all parent width and height. localvideoview is always bring to back . I try all possible codes but I can not see localview. I use localvideoView.bringToFront(); but without success.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<SlidingDrawer
android:id="#+id/drawer"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:content="#+id/content"
android:handle="#+id/handle"
android:orientation="horizontal"
android:rotation="180" >
<ImageView
android:id="#id/handle"
android:layout_width="50dip"
android:layout_height="50dip"
android:rotation="180"
android:src="#drawable/ic_launcher" />
<LinearLayout
android:id="#id/content"
android:layout_width="250dp"
android:layout_height="fill_parent"
android:background="#0000ff"
android:orientation="vertical"
android:rotation="180" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
</LinearLayout>
</SlidingDrawer>
I want to change the icon position and put it on the top position from left to right
Is anyone who can tell me how it to set this custom icon position on android slider drawer>
Thanks in advance
http://i.stack.imgur.com/q8dz2.png
Take a look at your button:
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
You can set for it an icon in at least four ways (like in this picture):
You need only to specify where the Drawable should stay.
on the left of text:
android:drawableLeft="#mipmap/ic_launcher"
on the right of text:
android:drawableRight="#mipmap/ic_launcher"
at the top, text below:
android:drawableTop="#mipmap/ic_launcher"
at the bottom, text above:
android:drawableBottom="#mipmap/ic_launcher"
All you need is to add to your button layout one of these possible lines.
Of course to one button, you can add more than one drawable.
NOTE: Read also:
http://developer.android.com/guide/topics/ui/controls/button.html
Hope it help
EDIT: I haven't used SlidingDrawer before, so I cannot recognize, where the problem is, but always you can do a trick like this
<Button
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=""
android:drawableTop="#mipmap/ic_launcher"
android:layout_alignParentLeft="true"
android:layout_below="#id/handle"
android:background="#0000ff"
/>
This is a button with your desired image and "transparent" background.
Try it now and I would look for another solution ;-)
SOLUTION: Please try this code:
<SlidingDrawer
android:id="#+id/drawer"
android:layout_width="200dp"
android:layout_height="wrap_content"
android:content="#+id/content"
android:handle="#+id/handle"
android:orientation="horizontal"
android:rotation="180" >
<ImageView
android:id="#id/handle"
android:layout_width="50dip"
android:layout_height="50dip"
android:rotation="180"
android:src="#mipmap/ic_launcher" />
<LinearLayout
android:id="#id/content"
android:layout_width="250dp"
android:layout_height="fill_parent"
android:background="#0000ff"
android:orientation="vertical"
android:rotation="180" >
<ImageView
android:id="#id/handle"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:src="#mipmap/ic_launcher" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Big Big Button" />
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
If you still have any question please free to ask
Sliding drawer is deprecated, and is hard to use but I made a replacement. The only problem about it is that it doesn't slide like the sliding drawer, but it does apear and disapear. Here is the XML part:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:background="#acacac"
android:layout_height="100dp"
android:id="#+id/etc"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Menu"
android:id="#+id/bMenu"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:background="#drawable/button_shape_1"
/>
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_above="#+id/etc"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:visibility="gone"
android:id="#+id/menuContent">
//content
</RelativeLayout>
</RelativeLayout>
</FrameLayout>
This will by default(on copy/paste) not be shown(half the point)
It must be a framelayout as they allow item to be layed on top of eachother(the root element that is)
The code part:
RelativeLayout menuContent;
Button showMenu;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.game);
menuContent = (RelativeLayout) findViewById(R.id.menuContent);
showMenu = (Button) findViewById(R.id.bMenu);
showMenu.setOnClickListener(this);
}
boolean menuActive = false;
#Override
public void onClick(View v) {
switch (v.getId()){
case R.id.bMenu:
if(menuActive){
menuActive = false;
menuContent.setVisibility(View.GONE);
}else if(!menuActive){
menuActive = true;
menuContent.setVisibility(View.VISIBLE);
}
break;
}
}
This was copied out of a part of one of my newest games, so if it doesn't work as it sits, let me know and I will take a look at it
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 an xml layout of about 3000 lines, which serves as the layout for a questionnaire type of app. Each page of the questionnaire is inside of a different linear layout and I set the visibility of the linear layouts in code using View.GONE or View.VISIBLE. This way the user can navigate through the pages without loading new intents each time.
However, when I navigate fast through the app (just pressing the next button to go through the screens), some of the elements that are supposed to be View.GONE shows up and overlaps over the VISIBLE items. This only happens with linear layouts that have list views inside of them. For all the other pages.
I can scroll fast through them, but just the ones with list views in the View.GONE elements sometimes shows up when I navigate too fast. How can I fix this ? Let me know if you want code ... however the xml is very large.
T.I.A.
EDIT
This is a sample of my xml code, I have 3000 lines of this repeating in my xml...
<LinearLayout
android:id="#+id/package_normal_samplesblood"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="70dp"
android:orientation="vertical">
<TextView
android:id="#+id/textview_heading_b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="23sp"
android:layout_marginLeft="13dp"
android:layout_marginRight="10dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:textColor="#6f6f6f"
android:layout_gravity="left"
android:text="Blood Samples"/>
<Button
android:id="#+id/button_samples_blood"
android:text="Add Blood Samples"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:textSize="20sp"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
<ListView
android:id="#+id/listview_samples_blood"
android:scrollbarSize="0dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical"
/>
</LinearLayout>
<RelativeLayout
android:orientation="horizontal"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:layout_marginTop="-75dp"
>
<View
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_height="1dp"
android:background="#DEDEDE"
android:layout_marginTop="2dp"/>
<ImageButton
android:id="#+id/left9"
android:background="#null"
android:scaleType="fitEnd"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_width="70px"
android:layout_height="70px"
android:src="#drawable/left"/>
<TextView
android:id="#+id/textview_heading2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:textColor="#6f6f6f"
android:layout_gravity="center"
android:text="RhODIS®"/>
<ImageButton
android:id="#+id/right9"
android:background="#null"
android:scaleType="fitEnd"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_width="70px"
android:layout_height="70px"
android:src="#drawable/right"/>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/package_normal_sampleshair"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="70dp"
android:orientation="vertical">
<TextView
android:id="#+id/textview_heading_b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="23sp"
android:layout_marginLeft="13dp"
android:layout_marginRight="10dp"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:textColor="#6f6f6f"
android:layout_gravity="left"
android:text="Hair Samples"/>
<Button
android:id="#+id/button_samples_hair"
android:text="Add Hair Samples"
android:layout_width="fill_parent"
android:layout_height="65dp"
android:textSize="20sp"
android:layout_gravity="center"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"/>
<ListView
android:id="#+id/listview_samples_hair"
android:scrollbarSize="0dp"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#ffffff"
android:orientation="vertical"
/>
</LinearLayout>
<RelativeLayout
android:orientation="horizontal"
android:background="#ffffff"
android:layout_width="fill_parent"
android:layout_height="75dp"
android:layout_marginTop="-75dp"
>
<View
android:layout_width="fill_parent"
android:layout_alignParentTop="true"
android:layout_height="1dp"
android:background="#DEDEDE"
android:layout_marginTop="2dp"/>
<ImageButton
android:id="#+id/left10"
android:background="#null"
android:scaleType="fitEnd"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginTop="10dp"
android:layout_marginLeft="10dp"
android:layout_width="70px"
android:layout_height="70px"
android:src="#drawable/left"/>
<TextView
android:id="#+id/textview_heading2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:layout_centerInParent="true"
android:layout_marginTop="10dp"
android:textColor="#6f6f6f"
android:layout_gravity="center"
android:text="RhODIS®"/>
<ImageButton
android:id="#+id/right10"
android:background="#null"
android:scaleType="fitEnd"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"
android:layout_width="70px"
android:layout_height="70px"
android:src="#drawable/right"/>
</RelativeLayout>
</LinearLayout>
And then this is a sample of how I show and hide the linear layouts in code, this repeats for 24 left buttons and 24 right buttons:
left24.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
package_normal_welcomescreen.setVisibility(View.GONE);
package_normal_package_details.setVisibility(View.GONE);
package_normal_openbag.setVisibility(View.GONE);
package_normal_kitnumber.setVisibility(View.GONE);
package_normal_emptybag.setVisibility(View.GONE);
package_normal_gpscoordinates.setVisibility(View.GONE);
package_normal_image_scene.setVisibility(View.GONE);
package_normal_samplesblood.setVisibility(View.GONE);
package_normal_sampleshair.setVisibility(View.GONE);
package_normal_samplestissue.setVisibility(View.GONE);
package_normal_sampleshorn.setVisibility(View.GONE);
package_normal_samplesother.setVisibility(View.GONE);
package_normal_packsamples.setVisibility(View.GONE);
package_normal_returnbag.setVisibility(View.GONE);
package_normal_sealreturnbag.setVisibility(View.GONE);
package_normal_image_sealedbag.setVisibility(View.GONE);
package_normal_scanned.setVisibility(View.GONE);
package_normal_animal_details.setVisibility(View.GONE);
package_normal_animal_horn_details.setVisibility(View.GONE);
package_normal_animal_ears.setVisibility(View.GONE);
package_normal_area_details.setVisibility(View.GONE);
package_normal_collecter_details.setVisibility(View.GONE);
package_normal_additional_information.setVisibility(View.GONE);
package_normal_owner_details.setVisibility(View.VISIBLE);
package_normal_owner_details.bringToFront();
}
});
right24.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v)
{
if(Session.signatureIsCaptured)
{
package_normal_welcomescreen.setVisibility(View.GONE);
package_normal_package_details.setVisibility(View.GONE);
package_normal_openbag.setVisibility(View.GONE);
package_normal_kitnumber.setVisibility(View.GONE);
package_normal_emptybag.setVisibility(View.GONE);
package_normal_gpscoordinates.setVisibility(View.GONE);
package_normal_image_scene.setVisibility(View.GONE);
package_normal_samplesblood.setVisibility(View.GONE);
package_normal_sampleshair.setVisibility(View.GONE);
package_normal_samplestissue.setVisibility(View.GONE);
package_normal_sampleshorn.setVisibility(View.GONE);
package_normal_samplesother.setVisibility(View.GONE);
package_normal_packsamples.setVisibility(View.GONE);
package_normal_returnbag.setVisibility(View.GONE);
package_normal_sealreturnbag.setVisibility(View.GONE);
package_normal_image_sealedbag.setVisibility(View.GONE);
package_normal_scanned.setVisibility(View.GONE);
package_normal_animal_details.setVisibility(View.GONE);
package_normal_animal_horn_details.setVisibility(View.GONE);
package_normal_animal_ears.setVisibility(View.GONE);
package_normal_area_details.setVisibility(View.GONE);
package_normal_owner_details.setVisibility(View.GONE);
package_normal_collecter_details.setVisibility(View.GONE);
package_normal_additional_information.setVisibility(View.VISIBLE);
package_normal_additional_information.bringToFront();
}
else
{
Toast.makeText(Screen_Package_Normal.this, "Authorized Signature Required", Toast.LENGTH_LONG).show();
}
}
});
I have different types of listviews and adapters, custom and android built in. I don't think the problem lies with the adapter since it works pretty well displaying the listviews and the problem occurs even before the listviews are populated...
I have a temporary fix, not sure how correct this is as an answer, but this fixed my problem... I applied this to my entire layout, and it adds an animation when I hide and show layouts, thus slowing them down a bit, removing the overlapping elements from showing up.
This is what I added to my layout:
android:animateLayoutChanges="true"