Prevent certain views from being animated with android:animateLayoutChanges="true" - android

I have a horizontal linear layout that has 3 views. An open and close button and a text view. On load the close button is set to
setVisibility(View.GONE);
So it is only showing one imageview, open, and a textview with some text. I am also using
android:animateLayoutChanges="true"
On my parent layout to animate the textview when it opens and closes. Everything functions right except when I open/close I can see the animation for the two buttons being set to GONE and VISIBLE respectively. I do not want animation on those two ImageViews. Any thoughts on how I can remove the animations on those two views? Thanks in advance.
XML File
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
android:id="#+id/CuFScrollView"
style="#style/ScrollView"
xmlns:android="http://schemas.android.com/apk/res/android"
android:background="#A0A0A0"
>
<LinearLayout
style="#style/LinearLayoutVertical"
android:paddingTop="20dp"
>
<TextView
android:text="Basic Management Plan for Tactical Field Care"
android:id="#+id/header"
style="#style/Header"
/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#606060"
android:padding="5dp"
android:animateLayoutChanges="true"
>
<ImageView
android:id="#+id/open"
android:src="#drawable/open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:onClick="open"
android:layout_gravity="center_vertical"
android:animateLayoutChanges="false"
/>
<ImageView
android:id="#+id/close"
android:src="#drawable/close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:onClick="close"
android:layout_gravity="center_vertical"
android:animateLayoutChanges="false"
/>
<TextView
android:id="#+id/stepOne"
android:text="Step 1:"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="0dp"
style="#style/Bullet"
/>
</LinearLayout>
</LinearLayout>
Java File
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;
import android.widget.ScrollView;
import android.widget.TextView;
public class Careunderfirestudy extends AppCompatActivity{
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getSupportActionBar().hide();
setContentView(R.layout.careunderfirestudy);
ImageView close = (ImageView)findViewById(R.id.close);
close.setVisibility(View.GONE);
}
public void open(View view){
TextView stepOne = (TextView)findViewById(R.id.stepOne);
stepOne.setText("Casualties should be extricated from burning vehicles or buildings and moved to places of relative safety. Do what is necessary to stop the burning process.");
ImageView close = (ImageView)findViewById(R.id.close);
ImageView open = (ImageView)findViewById(R.id.open);
close.setVisibility(View.VISIBLE);
open.setVisibility(View.GONE);
}
public void close(View view){
TextView stepOne = (TextView)findViewById(R.id.stepOne);
stepOne.setText("Step 1:");
ImageView close = (ImageView)findViewById(R.id.close);
ImageView open = (ImageView)findViewById(R.id.open);
close.setVisibility(View.GONE);
open.setVisibility(View.VISIBLE);
}
}

The question was: Prevent certain views from being animated with android:animateLayoutChanges=“true” and I don't see the answer to this question in the previous answer.
I had the same problem and I solved it disabling temporary the LayoutTransition for appearing and disappearing type.
Here examples.
Hide a View without animating it:
LayoutTransition lt = ((ViewGroup)view.getParent()).getLayoutTransition();
lt.disableTransitionType( LayoutTransition.DISAPPEARING );
view.setVisibility(View.GONE);
lt.enableTransitionType( LayoutTransition.DISAPPEARING );
Show a View without animating it:
LayoutTransition lt = ((ViewGroup)view.getParent()).getLayoutTransition();
lt.disableTransitionType( LayoutTransition.APPEARING );
view.setVisibility(View.VISIBLE);
lt.enableTransitionType( LayoutTransition.APPEARING );
This does not prevent other views to be animated consequently to the view visibility change (they are animated under LayoutTransition.CHANGE_APPEARING and LayoutTransition.CHANGE_DISAPPEARING transition type).
Not null check to LayoutTransition may be done for safety.

You could just use 1 button and change the image:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="#606060"
android:padding="5dp"
android:animateLayoutChanges="true"
android:id="#+id/parent"
>
<ImageView
android:id="#+id/toggleStep"
android:src="#drawable/open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp"
android:onClick="toggle"
android:layout_gravity="center_vertical"
/>
protected void onCreate(Bundle savedInstanceState) {
...
LinearLayout parent = (LinearLayout) findViewById(R.id.parent);
parent.getLayoutTransition().enableTransitionType(LayoutTransition.CHANGING);
...
}
private boolean mOpen = false;
public void toggle(View view){
TextView stepOne = (TextView)findViewById(R.id.stepOne);
ImageView toggle = (ImageView)findViewById(R.id.toggleStep);
if(mOpen){
stepOne.setText("Step 1:");
toggle.setImageResource(R.drawable.open);
}
else{
stepOne.setText("Casualties should be extricated from burning vehicles or buildings and moved to places of relative safety. Do what is necessary to stop the burning process.");
toggle.setImageResource(R.drawable.close);
}
mOpen = !mOpen;
}

Related

How to convert a CardView XML with title and buttons into library on Android?

EDITED
The examples in google searches and the android documentation are basic, and my question is more complex.
What I do not know, is how to put multiple components together and turn it into a single component. CardView + LinearLayout + TextView + ImageView = Custom View.
If I have a basic example, of cardview with at least one button and a space for external content. It would be enough for me to figure out how to do the rest. This within the cardview extension class, because I also do not know how the extension will understand where to create the components
EDITED 2
Example
QUESTION
I was trying to create a method of using Cardview with an expandable button, and I was able to do this in XML. But I wanted to be able to create a library so I could reuse it in other cases.
I'll show you the source code of what I did.
Layout XML
<android.support.v7.widget.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="vertical">
<LinearLayout
android:id="#+id/cwlltitulobtn"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:orientation="horizontal">
<TextView
android:id="#+id/title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#### TITLE OF BUTTON ####"
android:textSize="18sp"
android:textStyle="bold"/>
<ImageView
android:id="#+id/imgarrowdown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:scaleType="fitEnd"
android:visibility="visible"
app:srcCompat="#drawable/ic_keyboard_arrow_down_black_24dp" />
<ImageView
android:id="#+id/imgarrowup"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0"
android:scaleType="fitEnd"
android:visibility="gone"
app:srcCompat="#drawable/ic_keyboard_arrow_up_black_24dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/cwllconteudo"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:visibility="gone">
<!-- ########################################
######## CARDVIEW CONTENT HERE #########
########################################-->
</LinearLayout>
</LinearLayout>
</android.support.v7.widget.CardView>
Java code
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
findViewById(R.id.cwlltitulobtn).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
CVOpenCloseBTN();
}
});
}
public void CVOpenCloseBTN(){
ImageView arrowdown = (ImageView) findViewById(R.id.cvimgarrowdown);
ImageView arrowup = (ImageView) findViewById(R.id.cvimgarrowup);
LinearLayout pagecontent = (LinearLayout) findViewById(R.id.cwllconteudo);
if (conteudopage .getVisibility() == View.GONE) {
// it's collapsed - expand it
pagecontent.setVisibility(View.VISIBLE);
arrowdown.setVisibility(View.GONE);
arrowup.setVisibility(View.VISIBLE);
} else {
// it's expanded - collapse it
pagecontent.setVisibility(View.GONE);
arrowdown.setVisibility(View.VISIBLE);
arrowup.setVisibility(View.GONE);
}
}
}
My idea is that I can transform all this part of the xml and java code to be used in this way and faster, than to have to always repeat again:
<br.com.samantabiblioteca.CardView
android:id="#+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardCornerRadius="5dp"
app:titulo="#### TITLE OF BUTTON ####">
<!-- ########################################
######### CARDVIEW CONTENT HERE ########
########################################-->
</br.com.samantabiblioteca.CardView>
Is it possible to do this?

How Whatsapp attachment's window can override keyboard?

I'm working on a similiar problem developing my chat and I was checking on how whatsapp solves it to get an idea to work on it.
On mobile and inside a conversation, when your keyboard is up on the screen and you click on attachments, the attachments window overrides the keboard like the image below. It also look likes the activity under it freezes ( you can look at the slash "|" on the EditText, it seems that is freeze ).
I was wondering how WP could override the keyboard and why it looks like the activity under it is freezing, thanks in advance!
/Use the below code Snipet without using any library/
action_attach.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
openDialog();
}
});
private void openDialog() {
LayoutInflater layoutInflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// inflate the custom popup layout
final View inflatedView;
inflatedView = layoutInflater.inflate(R.layout.custom_dialog_options_menu, null, false);
LinearLayout layoutGallery;
layoutGallery = (LinearLayout) inflatedView.findViewById(R.id.layoutGallery);
layoutGallery.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
FloatingView.dismissWindow();
}
});
FloatingView.onShowPopup(this, inflatedView);
}
/**Sample Layout for Pop Up window ie: custom_dialog_options_menu
and change layout according to your choice***/
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingTop="82dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFF"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/layoutGallery"
android:layout_width="0dp"
android:layout_marginTop="18dp"
android:layout_height="wrap_content"
android:layout_marginLeft="40dp"
android:layout_weight="1"
android:orientation="vertical">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:src="#drawable/gallery_attach_icon_selector"/>
<TextView
android:id="#+id/tvGallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Gallery"
android:layout_marginTop="10dp"
android:textSize="16sp"
android:textColor="#4d4747"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layoutPhoto"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_marginTop="18dp"
android:orientation="vertical">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:src="#drawable/camera_attach_icon_selector"/>
<TextView
android:id="#+id/tvPhoto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Camera"
android:layout_marginTop="10dp"
android:textSize="16sp"
android:textColor="#4d4747"/>
</LinearLayout>
<LinearLayout
android:id="#+id/layoutVideo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="40dp"
android:layout_weight="1"
android:layout_marginTop="18dp"
android:orientation="vertical">
<ImageView
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_gravity="center"
android:src="#drawable/video_attach_icon_selector"/>
<TextView
android:id="#+id/tvVideo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:text="Video"
android:layout_marginTop="10dp"
android:textSize="16sp"
android:textColor="#4d4747"/>
</LinearLayout>
</LinearLayout>
</LinearLayout>
/**FloatingView Class**/
public class FloatingView
{
/* Floating view is used to display a custom view for attachments in the chat screen */
import android.app.Activity;
import android.graphics.Point;
import android.view.Display;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.widget.PopupWindow;
private static PopupWindow popWindow;
private FloatingView() {
}
public static void onShowPopup(Activity activity, View inflatedView) {
// get device size
Display display = activity.getWindowManager().getDefaultDisplay();
final Point size = new Point();
display.getSize(size);
// fill the data to the list items
// set height depends on the device size
popWindow = new PopupWindow(inflatedView, size.x, ViewGroup.LayoutParams.WRAP_CONTENT,
true);
// set a background drawable with rounders corners
popWindow.setBackgroundDrawable(activity.getResources().getDrawable(
R.drawable.comment_popup_bg));
// make it focusable to show the keyboard to enter in `EditText`
popWindow.setFocusable(true);
// make it outside touchable to dismiss the popup window
popWindow.setOutsideTouchable(true);
popWindow.setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_ADJUST_PAN);
// show the popup at bottom of the screen and set some margin at
// bottom ie,
popWindow.showAtLocation(activity.getCurrentFocus(), Gravity.BOTTOM, 0,
0);
}
public static void dismissWindow() {
popWindow.dismiss();
}

How to translate image across the width of relativelayout in android

I'm trying to animate two images one from left to right and other from right to left all at the same time. For this I have set the left margin for left image equal to negative of its width and same for right image so that they are out of the view.
Now in my mainactivity I'm translating them using translationX but nothing is happening.
Here is xml file
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/bg"
tools:context="com.example.BeX.MainActivity" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="200dp"
android:layout_height="133dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/logo" />
<ImageView
android:id="#+id/left"
android:layout_width="100dp"
android:layout_height="75dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="-100dp"
android:src="#drawable/left" />
<ImageView
android:id="#+id/right"
android:layout_width="114dp"
android:layout_height="75dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="-114dp"
android:src="#drawable/right" />
</RelativeLayout>
Here is mainactivity.java
import android.app.Activity;
import android.os.Bundle;
import android.widget.ImageView;
import android.widget.RelativeLayout;
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setTheme(R.style.AppBaseTheme1);
setContentView(R.layout.activity_main);
RelativeLayout r = (RelativeLayout)findViewById(R.id.rLayout);
ImageView left = (ImageView)findViewById(R.id.left);
ImageView right = (ImageView)findViewById(R.id.right);
left.animate().translationX(r.getWidth()).setDuration(2000);
right.animate().translationX(-r.getWidth()).setDuration(2000);
}
}
Please tell me what is the correct or possible way to do that
Thanks in advance
There are two base types of Animation in Android.
The first one.
In order to animate translation use this example:
TranslateAnimation r = new TranslateAnimation(0,0,0,200);
r.setDuration(2000L);
r.setRepeatCount(0);
r.setFillAfter(true);
view.startAnimation(r);
The second one.
In your case, you use ViewPropertyAnimator class.
This is the second implementation of animation in Android.
left.animate().translationX(r.getWidth()).setDuration(2000)
In your case you have setup the Object animator but you haven't started it.
try this:
left.animate().translationX(r.getWidth()).setDuration(2000).start() :)
EDIT
This have to work:
XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/rLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#null">
<ImageView
android:id="#+id/imageView1"
android:layout_width="200dp"
android:layout_height="133dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/aqu" />
<ImageView
android:id="#+id/left"
android:layout_width="100dp"
android:layout_height="75dp"
android:src="#drawable/ar" />
<ImageView
android:id="#+id/right"
android:layout_width="114dp"
android:layout_height="75dp"
android:src="#drawable/ari" />
</RelativeLayout>
Java-file
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.dat);
RelativeLayout r = (RelativeLayout)findViewById(R.id.rLayout);
ImageView left = (ImageView)findViewById(R.id.left);
ImageView right = (ImageView)findViewById(R.id.right);
float distance = 300.f;
TranslateAnimation anim = new TranslateAnimation(0,0,0,distance);
anim.setFillAfter(true);
anim.setDuration(12000L);
left.startAnimation(anim);
}
But anyway if you want to animate using your ide write this:
ObjectAnimator anim0 = ObjectAnimator.ofFloat(right, "translationX", 0,300);
anim0.setDuration(10000L);
anim0.start();
It really works. I've tested.

Button visibility problems in Android

I'm creating a toolbar that toggles the visibility of buttons when you click a button from a toolbar. So, if the user clicks on the "Draw" button, invisible buttons "Pencil" and Pen" will become visible above the "Draw" button. If you click the "Draw" button again, the buttons "Pencil" and "Pen" will become invisible again.
Within my xml file I have set the visibilty of some buttons to be "invisible" so when I launch the activity they won't be seen. This part is straight forward.
.xml file of btnDrawLine - (Update # 12:21)
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent" >
<com.odhranlynch.testSection.UserInterface
android:id="#+id/UserInterface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentTop="true" />
<Button
android:id="#+id/btnDraw"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Draw" />
<Button
android:id="#+id/btnDrawLine"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_above="#+id/btnDraw"
android:layout_alignParentLeft="true"
android:visibility="visible"
android:text="Line" />
<Button
android:id="#+id/btnDrawCurve"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_above="#+id/btnDrawLine"
android:layout_alignParentLeft="true"
android:visibility="visible"
android:text="Curve" />
<Button
android:id="#+id/btnCutout"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/btnDraw"
android:text="Cutout" />
<Button
android:id="#+id/btnCutInner"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_above="#+id/btnDraw"
android:layout_toRightOf="#+id/btnDraw"
android:visibility="visible"
android:text="Inner" />
<Button
android:id="#+id/btnCutOutter"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/btnDrawCurve"
android:layout_alignBottom="#+id/btnDrawCurve"
android:layout_toLeftOf="#+id/btnCancel"
android:visibility="visible"
android:text="Outter" />
<Button
android:id="#+id/btnCancel"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toLeftOf="#+id/btnFinish"
android:text="Cancel" />
<Button
android:id="#+id/btnFinish"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:text="Finish" />
</RelativeLayout>
Next, when the user clicks a button that is visible, I'd like the invisible buttons to appear.
Here's the thing, they won't reappear!lol I'm confused by it.
I would be very grateful if someone would be kind enough to shed so light onto this for me :)
testActivity.java
package com.odhranlynch.testSection;
import com.odhranlynch.testSection.R;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
public class testActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_product);
// Find buttons and give them a name.
final View btnDraw = findViewById(R.id.btnDraw);
final View btnCutOut = findViewById(R.id.btnCutout);
final View btnDrawLine = findViewById(R.id.btnDrawLine);
final View btnDrawCurve = findViewById(R.id.btnDrawCurve);
final View btnCutInner = findViewById(R.id.btnCutInner);
final View btnCutOutter = findViewById(R.id.btnCutOutter);
//Draw Button clicked (UI Toolbar).
btnDraw.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
//Treat button as a toggle button
//So if a sub-button (e.g. Draw Line) is visible, then we know the button has
//been toggled to visible so lets now make it invisible.
if (btnDrawLine.getVisibility()== View.VISIBLE) {
//Its visible.
btnDrawLine.setVisibility(View.INVISIBLE);
btnDrawCurve.setVisibility(View.INVISIBLE);
Log.d("TAG", "INVISIBLE");
} else {
// Either gone or invisible
btnDrawLine.setVisibility(View.VISIBLE);
btnDrawCurve.setVisibility(View.VISIBLE);
Log.d("TAG", "VISIBLE");
}
}
});
}
}
As a further point to mention, if I set the visibilty of the buttons to be visible within the .xml file I can toggle the visibilty perfectly fine during runtime!
Again, I would be grateful of some help :)
Try replacing View.INVISIBLE to View.GONE.
Your code is working fine..
The XML file
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="#string/hello" />
<Button
android:id="#+id/btnDrawLine"
android:layout_width="80dip"
android:layout_height="wrap_content"
android:layout_above="#+id/btnDraw"
android:layout_alignParentLeft="true"
android:visibility="invisible"
android:text="Line" />
<Button
android:id="#+id/draw"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="draw" />
</LinearLayout>
The activity
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class DrawCanvasActivity extends Activity {
private static final String Number1 = "9686801147";
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final View btnDrawLine = findViewById(R.id.btnDrawLine);
Button btnDraw = (Button) findViewById(R.id.draw);
btnDraw.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
if (btnDrawLine.getVisibility()== View.VISIBLE) {
btnDrawLine.setVisibility(View.INVISIBLE);
Log.d("TAG", "INVISIBLE");
} else {
btnDrawLine.setVisibility(View.VISIBLE);
Log.d("TAG", "VISIBLE");
}
}
});
}
}
The button line appears when the draw button is clicked.Guess there may be problem in the view formatting in your code.
If you want ot use gone/visible, just add a LinearLayout around your buttons, which you want to hide. LinearLayout will have a layout_width=wrap_content; and you referer position of other element to this Layout.
After you free to change visibility to gone/visible of your buttons.

Android sliding menu to change content on page can this be done?

The main page has a horizontalScrollView across the top and a number of TextView text fields within it. I would like to be able to scroll and click on any on the TextView text and it change the RelativeLayout to match the selection made in the HorizontalScrollView.
main.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<HorizontalScrollView android:id="#+id/horizontalScrollView1" android:layout_height="wrap_content" android:scrollbars="none" android:layout_width="wrap_content">
<LinearLayout android:layout_width="match_parent" android:orientation="horizontal" android:layout_height="match_parent" android:id="#+id/linearLayout1">
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="#+id/EditTOne" android:text="tOne"></TextView>
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="#+id/EditTTwo" android:text="tTwo"></TextView>
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="#+id/EditTThree" android:text="tThree"></TextView>
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="#+id/EditTFour" android:text="tFour"></TextView>
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="#+id/EditTFive" android:text="tFive"></TextView>
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="#+id/EditTSix" android:text="tSix"></TextView>
<TextView android:layout_height="wrap_content" android:layout_weight="1" android:layout_width="70dp" android:id="#+id/EditTSeven" android:text="tSeven"></TextView>
</LinearLayout>
</HorizontalScrollView>
<RelativeLayout android:layout_height="wrap_content" android:layout_width="match_parent" android:id="#+id/relativeLayout1"></RelativeLayout>
</LinearLayout>
I have a second layout page called tone which would be linked to the menu option tOne in the HorizontalScrollView.
tone.xml
<?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">
<TextView android:id="#+id/textView1" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="This is tOne"></TextView>
</LinearLayout>
The main activity will flag if one of the first 4 options are selected by writing to the LogCat. Is it possible to display the tone.xml within the relativelayout if the user clicks the tOne option from the HorizontalScrollView? Then if the user selects tTwo display ttwo.xml in the RelativeLayoutView etc?
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.RelativeLayout;
import android.widget.TextView;
public class SlideMenu extends Activity implements OnClickListener {
/** Called when the activity is first created. */
TextView tOne, tTwo, tThree, tFour, tFive, tSix, tSeven, tEight, tNine, tTen;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
RelativeLayout vSpace = (RelativeLayout)findViewById(R.id.relativeLayout1);
tOne = (TextView)findViewById(R.id.EditTOne);
tTwo = (TextView)findViewById(R.id.EditTTwo);
tThree = (TextView)findViewById(R.id.EditTThree);
tFour = (TextView)findViewById(R.id.EditTFour);
tFive = (TextView)findViewById(R.id.EditTFive);
tSix = (TextView)findViewById(R.id.EditTSix);
tSeven = (TextView)findViewById(R.id.EditTSeven);
tOne.setOnClickListener(this);
tTwo.setOnClickListener(this);
tThree.setOnClickListener(this);
tFour.setOnClickListener(this);
tFive.setOnClickListener(this);
tSix.setOnClickListener(this);
tSeven.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
switch(v.getId()) {
//--------------
case R.id.EditTOne:
System.out.println("Text One pressed");
break;
case R.id.EditTTwo:
System.out.println("Text Two pressed");
break;
case R.id.EditTThree:
System.out.println("Text Three pressed");
break;
case R.id.EditTFour:
System.out.println("Text Four pressed");
break;
}
}
}
I believe it is fairly simple. I added
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.tone, vSpace);
after you print "Text One Pressed". Be sure to make vSpace a field first.
To do this with all of them, call
vSpace.removeAllViews()
before you inflate each view.

Categories

Resources