Avd showing old version of my application - android

So i've make some change's in my app (it was about nesting layouts - My root layout, was linear layout,i wanted to change it to relative layout,i remember,it was something wrong with lines like xlmns:tools etc. I've copy those lines from my previous app,but then i've got an error that something is missing,so i google it,and somebody wrote about delete .idea and .gradle folders so i did,and now,my avd showing me "old content" just app before some changes. How i can solve it? The application that i've trying to make,it's just an typical clicker at case of my course. It's about to counting score of two teams. Screen with an issue https://imgur.com/a/U9gianT
<?xml version="1.0" encoding="utf-8"?>
<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:layout_height="match_parent"
android:layout_width="match_parent">
<Button
android:layout_gravity="center"
android:id="#+id/reset_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/resetBTN"
android:layout_marginTop="15dp"
android:onClick="reset_score"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="32dp"
/>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/team_a"
android:textSize="14sp"
android:textColor="#616161"
android:fontFamily="sans-serif-medium"
android:layout_marginTop="16dp"/>
<TextView
android:layout_gravity="center"
android:id="#+id/team_a_points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/team_a_points"
android:layout_marginTop="16dp"
android:textColor="#000000"
android:fontFamily="sans-serif-light"
android:textSize="56sp"/>
<Button
android:layout_gravity="center"
android:id="#+id/three_points_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_3_points_btn"
android:layout_marginTop="24dp"
android:onClick="addThreePointsA"/>
<Button
android:layout_gravity="center"
android:id="#+id/two_points_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_points_btn"
android:layout_marginTop="24dp"
android:onClick="addTwoPointsA"/>
<Button
android:layout_gravity="center"
android:id="#+id/free_throw_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/free_throw_btn"
android:layout_marginTop="24dp"
android:onClick="addOnePointA"/>
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="340dp"
android:background="#android:color/darker_gray"
android:layout_marginTop="15dp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:layout_marginTop="16dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/team_b"
android:textSize="14sp"
android:textColor="#616161"
android:fontFamily="sans-serif-medium"/>
<TextView
android:layout_gravity="center"
android:id="#+id/team_b_points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/team_b_score"
android:layout_marginTop="16dp"
android:textSize="56sp"
android:textColor="#000000"
android:fontFamily="sans-serif-light"/>
<Button
android:layout_gravity="center"
android:id="#+id/three_points_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_3_points_btn"
android:layout_marginTop="24dp"
android:onClick="addThreePointsB"/>
<Button
android:layout_gravity="center"
android:id="#+id/two_points_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_points_btn"
android:layout_marginTop="24dp"
android:onClick="addTwoPointsB"/>
<Button
android:layout_gravity="center"
android:id="#+id/free_throw_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/free_throw_btn"
android:layout_marginTop="24dp"
android:onClick="addOnePointB"/>
</LinearLayout>
package com.example.kacper.courtcounter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
int team_a_score = 0;
int team_b_score = 0;
private void display_a_score(int score){
TextView scoreView = (TextView) findViewById(R.id.team_a_points);
scoreView.setText(String.valueOf(score));
}
private void display_b_score(int score){
TextView scoreView = (TextView) findViewById(R.id.team_b_points);
scoreView.setText(String.valueOf(score));
}
public void addThreePointsA(View view) {
team_a_score = team_a_score+3;
display_a_score(team_a_score);
}
public void addTwoPointsA(View view) {
team_a_score = team_a_score+2;
display_a_score(team_a_score);
}
public void addOnePointA(View view) {
team_a_score = team_a_score+1;
display_a_score(team_a_score);
}
public void addThreePointsB(View view) {
team_b_score = team_b_score+3;
display_b_score(team_b_score);
}
public void addTwoPointsB(View view) {
team_b_score = team_b_score+2;
display_b_score(team_b_score);
}
public void addOnePointB(View view) {
team_b_score = team_b_score+1;
display_b_score(team_b_score);
}
public void reset_score(View view) {
team_a_score = 0;
team_b_score = 0;
display_a_score(team_a_score);
display_b_score(team_b_score);
}
}

Just Clean and rebuild your project and then uninstall app from device and then run again in device it will works fine (If you really make changes in code)

Related

Piccaso Image not Loading

My Image is Not loading ,when i was using Picaaso and Glide, And its give URL Path, when i was running the app. I also Attached the pHoto of Image which having error. I tried Everything,Even i used Glide library also.But Image was not loading and its give the app error.ALso there is no error in LOGCAT.Please help , i m new in this.
App Image Error
Master Fragment
public void initData(String authorization) {
ApiInterface apiInterface =
ApiClient.getClient().create(ApiInterface.class);
Call<List<MasterEventResponse>> call =
apiInterface.getAllDetail("Token "
+ authorization);
call.enqueue(new Callback<List<MasterEventResponse>>() {
#Override
public void onResponse(Call<List<MasterEventResponse>> call,
Response<List<MasterEventResponse>> response) {
Log.d(" MasterResponse", response.toString());
if (response.isSuccessful()) {
List<MasterEventResponse> masterResponse = response.body();
MasterEventResponse mMasterEventResponse;
for (int i = 0; i < masterResponse.size(); i++) {
String time = masterResponse.get(i).getStartTime();
Integer duration =
masterResponse.get(i).getEventDuration();
String topic = masterResponse.get(i).getTopic();
String name = masterResponse.get(i).getMasterName();
String image = masterResponse.get(i).getEventImage();
Integer id = masterResponse.get(i).getId();
mMasterEventResponse = new MasterEventResponse(id,
time, duration, topic, name, image);
masterEventResponse.add(mMasterEventResponse);
masterAdapter.notifyDataSetChanged();
} else {
Toast.makeText(context, "Something is crash.",
Toast.LENGTH_SHORT).show();
}
}
}
}
MasterAdapter
public class MasterAdapter extends
RecyclerView.Adapter<MasterAdapter.ViewHolder> {
#Override
public void onBindViewHolder(#NonNull ViewHolder holder, int position) {
holder.mTime.setText(masterEventResponse.get(position).getStartTime());
holder.mDuration.setText(Integer.toString(masterEventResponse.get(position).getEventDuration()));
holder.mDescription.setText(masterEventResponse.get(position).getTopic());
holder.mMentor.setText(masterEventResponse.get(position).getMasterName());
String url = masterEventResponse.get(position).getEventImage();
Picasso.get()
.load(url)
.resize(50, 50)
.placeholder(R.drawable.image)
.into(holder.mImage);
#Override
public int getItemCount() {
return masterEventResponse.size();
//return ();
}
public class ViewHolder extends RecyclerView.ViewHolder {
public TextView mTime;
public TextView mDuration;
public TextView mDescription;
public TextView mMentor;
public ImageView mImage;
// public LinearLayout mStatus;
public ViewHolder(#NotNull View itemView) {
super(itemView);
mTime = itemView.findViewById(R.id.tv_time);
mDuration= itemView.findViewById(R.id.tv_duration);
mDescription = itemView.findViewById(R.id.tv_detail);
mMentor = itemView.findViewById(R.id.tv_mentorName);
mImage = itemView.findViewById(R.id.img_master);
}
}
}
MOdel Class
Integer id, String masterName, Integer eventDuration,
String topic, String eventImage, String startTime) {
}
XML File
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
style="#style/Theme.Design.NoActionBar"
android:orientation="horizontal">
<androidx.cardview.widget.CardView
android:id="#+id/cv_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_weight="1"
android:background="#BACCD1"
app:cardCornerRadius="10dp"
app:cardElevation="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/image"
android:layout_width="match_parent"
android:layout_height="120dp">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:background="#BACCD1"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:layout_marginRight="5dp"
android:layout_marginBottom="10dp"
app:cardCornerRadius="5dp"
app:cardElevation="2dp">
<ImageView
android:id="#+id/img_master"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="#drawable/decor"/>
</androidx.cardview.widget.CardView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_marginLeft="10dp"
android:background="#BACCD1"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:layout_marginTop="5dp">
<TextView
android:id="#+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10:45AM"
android:layout_marginRight="50dp"
android:textSize="18sp"
android:textColor="#android:color/black"
/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_detail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Train your mind and get richer.."
android:textStyle="bold"
android:textColor="#color/black"
android:textSize="12sp"
android:layout_marginLeft="5sp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal">
<TextView
android:id="#+id/tv_mentorName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Sadhna Gupta"
android:layout_marginTop="35dp"
android:textColor="#color/black"
android:textSize="12sp"
android:layout_marginLeft="5sp" />
</LinearLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="30dp"
android:layout_alignParentBottom="true"
android:gravity="center_vertical">
<LinearLayout
android:id="#+id/ll_status"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<ImageView
android:id="#+id/img_corps"
android:layout_width="15dp"
android:layout_height="15dp"
android:src="#drawable/ic_corporate"
/>
<TextView
android:id="#+id/tv_corps"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Corporate"
android:textColor="#color/black"
android:textSize="12sp"
android:layout_marginLeft="5sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/lnl_restaurant"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:orientation="horizontal"
android:layout_alignParentRight="true"
android:layout_alignParentBottom="true"
android:gravity="center"
android:background="#drawable/ic_join">
<TextView
android:id="#+id/tv_join"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Join"
android:textColor="#845247"
android:textSize="12sp"/>
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
<RelativeLayout
android:id="#+id/lnl_favorite"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_margin="10dp"
android:layout_alignParentRight="true">
<TextView
android:id="#+id/tv_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="40 min"
android:layout_alignParentTop="true"/>
</RelativeLayout>
</RelativeLayout>
</LinearLayout>
</RelativeLayout>
</androidx.cardview.widget.CardView>

Buttons Overlap

I made a stopwatch using chronometer with four buttons but when i use the visibility modes to make stop and pause button appear they overlap.... Pls explain why...Below is the code.....
Assume the layout file with buttons in relative layout...
public class StopWatchFragment extends Fragment {
Chronometer chronometer;
Button startStopWatch;
Button stopStopWatch;
Button resetStopWatch;
Button pauseStopWatch;
Button resumeStopWatch;
private long lastPause;
//RelativeLayout relativeLayout;
private int check = 0;
public StopWatchFragment() {
// Required empty public constructor
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.stopwatch_layout,container,false);
chronometer = (Chronometer) rootView.findViewById(R.id.stopwatch);
startStopWatch = (Button) rootView.findViewById(R.id.startStopWatch);
stopStopWatch = (Button) rootView.findViewById(R.id.stopStopWatch);
resetStopWatch = (Button) rootView.findViewById(R.id.resetStopWatch);
pauseStopWatch = (Button) rootView.findViewById(R.id.pauseStopWatch);
resumeStopWatch = (Button) rootView.findViewById(R.id.resumeStopWatch);
relativeLayout = (RelativeLayout) rootView.findViewById(R.id.parentRelativeLayout);
pauseStopWatch.setVisibility(View.GONE);
//final RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(relativeLayout.getLayoutParams());
startStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
chronometer.setBase(SystemClock.elapsedRealtime());
chronometer.start();
startStopWatch.setVisibility(View.GONE);
pauseStopWatch.setVisibility(View.VISIBLE);
if(check == 1){
resumeStopWatch.setClickable(true);
}
else{
resumeStopWatch.setClickable(false);
}
//params.setMargins(16,16,16,16);
//pauseStopWatch.setLayoutParams(params);
}
});
pauseStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
check = 1;
lastPause = SystemClock.elapsedRealtime();
chronometer.stop();
}
});
resumeStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
chronometer.setBase(chronometer.getBase() + SystemClock.elapsedRealtime() - lastPause);
chronometer.start();
resumeStopWatch.setClickable(false);
}
});
stopStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
chronometer.stop();
startStopWatch.setVisibility(View.VISIBLE);
pauseStopWatch.setVisibility(View.GONE);
resumeStopWatch.setClickable(false);
}
});
resetStopWatch.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
chronometer.setBase(SystemClock.elapsedRealtime());
chronometer.stop();
resumeStopWatch.setClickable(false);
startStopWatch.setVisibility(View.VISIBLE);
pauseStopWatch.setVisibility(View.GONE);
}
});
return rootView;
}
}
This is the layout file pls refer for this....
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/parentRelativeLayout"
android:layout_height="match_parent"
android:padding="#dimen/activity_horizontal_margin">
<Chronometer
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textAlignment="center"
android:id="#+id/stopwatch"
android:layout_margin="16dp"/>
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/stopwatch">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<Button
android:id="#+id/startStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:background="#drawable/buttonshape"
android:textSize="24sp" />
<Button
android:id="#+id/pauseStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pause"
android:background="#drawable/buttonshape"
android:textSize="24sp" />
<Button
android:id="#+id/stopStopWatch"
android:layout_marginTop="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/startStopWatch"
android:background="#drawable/buttonshape"
android:text="Stop"
android:textSize="24sp"/>
<Button
android:id="#+id/resetStopWatch"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonshape"
android:text="Reset"
android:textSize="24sp" />
<Button
android:id="#+id/resumeStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonshape"
android:text="Resume"
android:textSize="24sp"
android:layout_marginTop="16dp"
android:layout_alignParentRight="true"
android:layout_below="#id/resetStopWatch"/>
</RelativeLayout>
</ScrollView>
</RelativeLayout>
This is the way buttons work when click on start button
You are hiding the button, but you are still listening with the OnClickListener. Try adding:
pauseStopWatch.setOnClickListener(null);
Then, when you make your button visible:
pauseStopWatch.setOnClickListener(whatever);
Try this layout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:id="#+id/parentRelativeLayout"
android:layout_height="match_parent"
android:padding="#dimen/activity_horizontal_margin">
<Chronometer
android:layout_centerInParent="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="30sp"
android:textAlignment="center"
android:id="#+id/stopwatch"
android:layout_margin="16dp"/>
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/stopwatch">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<LinearLayout
android:gravity="center"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<Button
android:id="#+id/startStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:background="#drawable/buttonshape"
android:textSize="24sp" />
<Button
android:visibility="gone"
android:id="#+id/pauseStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pause"
android:background="#drawable/buttonshape"
android:textSize="24sp" />
<Button
android:id="#+id/stopStopWatch"
android:layout_marginTop="16dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/startStopWatch"
android:background="#drawable/buttonshape"
android:text="Stop"
android:textSize="24sp"/>
</LinearLayout>
<LinearLayout
android:gravity="center"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<Button
android:id="#+id/resetStopWatch"
android:layout_alignParentRight="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonshape"
android:text="Reset"
android:textSize="24sp" />
<Button
android:id="#+id/resumeStopWatch"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/buttonshape"
android:text="Resume"
android:textSize="24sp"
android:layout_marginTop="16dp"
android:layout_alignParentRight="true"
android:layout_below="#id/resetStopWatch"/>
</LinearLayout>
</LinearLayout>
In the above, the pause button will be set to Gone. You make it visible later when user clicks start button

Android - Add subview after animation

I'm trying to add a subview below another view after an animation. anyone have any idea what i'm doing wrong?
this.animate().translationY(newY - 170).setDuration(500).withEndAction(new Runnable() {
#Override
public void run() {
clearAnimation();
RouteBreakDownLayout routeBreakDownLayout = new RouteBreakDownLayout(mContext);
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.BELOW, R.id.selected_route_layout);
routeBreakDownLayout.setLayoutParams(p);
addView(routeBreakDownLayout);
}
}).start();
Here is the XML for the layout. I have a scrollview embeded which will hold the content that needs to be animated in.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/selected_route_layout2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="bottom"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RelativeLayout
android:id="#+id/selected_route_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="bottom"
android:layout_alignParentBottom="true"
android:background="#FFF"
android:gravity="bottom"
android:padding="10dip">
<TextView
android:id="#+id/time_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#1D1C18" />
<TextView
android:id="#+id/eta_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/time_label"
android:layout_toEndOf="#+id/time_label"
android:layout_toRightOf="#+id/time_label"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#7EC82F" />
<LinearLayout
android:id="#+id/route_breakdown"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/time_label"
android:layout_centerVertical="true"
android:layout_marginBottom="10dip"
android:layout_marginTop="10dip"
android:gravity="center_vertical"
android:orientation="horizontal" />
<TextView
android:id="#+id/via_label"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/route_breakdown"
android:text="Medium Text"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#BDBDBD" />
<ImageButton
android:id="#+id/arrow_up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:background="#null"
android:padding="15dip"
android:src="#drawable/transit_symbol_up_arrow" />
</RelativeLayout>
<ScrollView
android:layout_below="#+id/selected_route_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:showDividers="middle"
android:divider="?android:dividerHorizontal"
android:animateLayoutChanges="true"
android:paddingLeft="16dp"
android:paddingRight="16dp" />
</ScrollView>
</RelativeLayout>
What goes wrong for you in your code-snippet?
Here's working example I came up with:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/containerRelativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<View
android:id="#+id/headerView"
android:background="#00FF00"
android:layout_width="match_parent"
android:layout_height="25dp"/>
<View
android:id="#+id/detailsView"
android:layout_alignParentBottom="true"
android:layout_width="match_parent"
android:layout_height="40dp"
android:clickable="true"
android:background="#FF0000"/>
</RelativeLayout>
And MainActivity is
package klogi.com.animationstestapp;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
final View detailsView = findViewById(R.id.detailsView);
final View headerView = findViewById(R.id.headerView);
final RelativeLayout container = (RelativeLayout)findViewById(R.id.containerRelativeLayout);
container.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
detailsView.animate().translationY(-detailsView.getY()).setDuration(500).withEndAction(new Runnable() {
#Override
public void run() {
Button additionalButton = new Button(MainActivity.this);
additionalButton.setText("Additional button");
RelativeLayout.LayoutParams additionalButtonParams = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
additionalButtonParams.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
additionalButton.setLayoutParams(additionalButtonParams);
container.addView(additionalButton);
}
}).start();
headerView.animate().translationY(detailsView.getHeight()).setDuration(500).start();
}
});
}
}
It works just as expected.
Have you tried to add your control(RouteBreakDownLayout) without animation? Does it work? It can be something like control is actually adding, but it's out of the viewport, etc. - so far, I can just guessing.

An alert dialog with an image will appear once LinearLayout is clicked

Symptoms.java
package com.example.des;
import java.util.ArrayList;
import com.example.des.R;
import com.example.des.Symptoms;
import com.example.des.Learn_Dengue;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.view.Gravity;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Toast;
public class Symptoms extends Activity implements OnClickListener{
//set variables
CheckBox q1; CheckBox q2; CheckBox q3; CheckBox q4; CheckBox q5; CheckBox q6;
CheckBox q7; CheckBox q8; CheckBox q9 ;CheckBox q10; CheckBox q11; CheckBox q12;
LinearLayout sas1; LinearLayout sas2; LinearLayout sas3; LinearLayout sas4; LinearLayout sas5; LinearLayout sas6;
LinearLayout sas7; LinearLayout sas8; LinearLayout sas9; LinearLayout sas10; LinearLayout sas11; LinearLayout sas12;
Button btndone;
Button btnlearn;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.question);
q1 = (CheckBox)findViewById(R.id.q1a); //Question number 1--main symptom
q2 = (CheckBox)findViewById(R.id.q2a);
q3 = (CheckBox)findViewById(R.id.q3a);
q4 = (CheckBox)findViewById(R.id.q4a);
q5 = (CheckBox)findViewById(R.id.q5a);
q6 = (CheckBox)findViewById(R.id.q6a);
q7 = (CheckBox)findViewById(R.id.q7a);
q8 = (CheckBox)findViewById(R.id.q8a);
q9 = (CheckBox)findViewById(R.id.q9a);
q10 = (CheckBox)findViewById(R.id.q10a);
q11 = (CheckBox)findViewById(R.id.q11a);
q12 = (CheckBox)findViewById(R.id.q12a);
sas1 = (LinearLayout)findViewById(R.id.sas1view);
sas2 = (LinearLayout)findViewById(R.id.sas2view);
sas3 = (LinearLayout)findViewById(R.id.sas3view);
sas4 = (LinearLayout)findViewById(R.id.sas4view);
sas5 = (LinearLayout)findViewById(R.id.sas5view);
sas6 = (LinearLayout)findViewById(R.id.sas6view);
sas7 = (LinearLayout)findViewById(R.id.sas7view);
sas8 = (LinearLayout)findViewById(R.id.sas8view);
sas9 = (LinearLayout)findViewById(R.id.sas9view);
sas10 = (LinearLayout)findViewById(R.id.sas10view);
sas11 = (LinearLayout)findViewById(R.id.sas11view);
sas12 = (LinearLayout)findViewById(R.id.sas12view);
btndone = (Button) findViewById(R.id.done);
btndone.setOnClickListener(this);
btnlearn = (Button) findViewById(R.id.learn);
btnlearn.setOnClickListener(this);
}
#Override
public void onClick(View v) {
// When button "Result" is pressed
switch (v.getId()) {
case R.id.done:
ArrayList<CheckBox> cbList = new ArrayList<CheckBox>();
// Array CheckBox 2 - 12 inside an Array (sub symptoms)
cbList.add((CheckBox)findViewById(R.id.q2a));
cbList.add((CheckBox)findViewById(R.id.q3a));
cbList.add((CheckBox)findViewById(R.id.q4a));
cbList.add((CheckBox)findViewById(R.id.q5a));
cbList.add((CheckBox)findViewById(R.id.q6a));
cbList.add((CheckBox)findViewById(R.id.q7a));
cbList.add((CheckBox)findViewById(R.id.q8a));
cbList.add((CheckBox)findViewById(R.id.q9a));
cbList.add((CheckBox)findViewById(R.id.q10a));
cbList.add((CheckBox)findViewById(R.id.q11a));
cbList.add((CheckBox)findViewById(R.id.q12a));
// Starts Looping if CheckBox number 1 is selected and the others (result SUSPICIOUS)
if (q1.isChecked()) {
int count = 0;
for (CheckBox cb : cbList) {
if (cb.isChecked()) {
count++;
}
}
if (count == 2 || count == 1 || count == 0) {
new AlertDialog.Builder(this).setMessage(R.string.suspicious).show();
}
}
// START Looping if CheckBox number 1 is selected but 11 and 12 are not (result MOST LIKELY)
if (q1.isChecked()) {
int count = 0;
for (CheckBox cb : cbList) {
if (cb.isChecked()) {
count++;
}
}
if (count >= 3 && count < 11) {
new AlertDialog.Builder(this).setMessage(R.string.most_likely).show();
}
}
// START Looping if all CheckBox are selected(result POSITIVE)
if (q1.isChecked() && q2.isChecked() && q3.isChecked() && q4.isChecked() &&
q5.isChecked() && q6.isChecked() && q7.isChecked() && q8.isChecked() &&
q9.isChecked() && q10.isChecked() && q11.isChecked() && q12.isChecked()) {
int count = 0;
for (CheckBox cb : cbList) {
if (cb.isChecked()) {
count++;
}
}
if (count == 11) {
new AlertDialog.Builder(this).setMessage(R.string.positive).show();
}
}
// Starts Looping if CheckBox number 1 is not selected and the others are checked
if (!q1.isChecked()) {
int count = 0;
for (CheckBox cb : cbList) {
if (cb.isChecked()) {
count++;
}
}
if (count <= 1 || count > 1) {
//this Toast will show when only 1 or more check box will be checked(excluding check box #1)
/*Toast toast= Toast.makeText(getApplicationContext(), getString(R.string.negative), Toast.LENGTH_LONG);
toast.setGravity(Gravity.CENTER, 0, 0);
toast.show();
*/
new AlertDialog.Builder(this).setMessage(R.string.negative).show();
}
}
break;
// When button "Learn More" is pressed
case R.id.learn:
Intent q = new Intent(this, Learn_Dengue.class);
startActivity(q);
break;
}
Here start my question.
sas1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas3.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas4.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas5.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas6.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas7.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas8.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas9.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas10.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas11.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
sas12.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
//Alert Dialog with image
}
});
}
}
questions.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/scrollView1"
style="#style/styleName"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/warning"
android:textAppearance="?android:attr/textAppearanceMedium" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q1a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas1view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas1"
android:layout_width="wrap_content"
android:layout_height="30dp"
android:text="#string/sas1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q2a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas2view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas2"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q3a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas3view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas3"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q4a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas4view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas4"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q5a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas5view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas5"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q6a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas6view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas6"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q7a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas7view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas7"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q8a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas8view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas8"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q9a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas9view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas9"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q10a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas10view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas10"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q11a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas11view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas11"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/q12a"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_marginTop="15dp"
android:id="#+id/sas12view"
android:layout_width="match_parent"
android:layout_height="30dp" >
<TextView
android:id="#+id/sas12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/sas12"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000"
android:textSize="15sp"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="20dp" >
<Button
android:id="#+id/done"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginLeft="35dp"
android:layout_marginTop="20dp"
android:background="#drawable/btn_orange"
android:text="#string/done"
android:textColor="#ffffff"
android:textSize="15sp" />
<Button
android:id="#+id/learn"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:background="#drawable/btn_black"
android:text="#string/learn"
android:textColor="#ffffff"
android:textSize="15sp" />
</LinearLayout>
</LinearLayout>
</ScrollView>
here is my full code as you requested #mobie.. the Symptoms.java and the question.xml..dont matter the other code..just on the alert dialog that i asked.
Create Layout Like Below for Dialog Box : dialog.xml
<?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" >
<ImageView
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginRight="5dp" />
<TextView
android:id="#+id/text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textColor="#FFF"
android:layout_toRightOf="#+id/image"/>
<Button
android:id="#+id/dialogButtonOK"
android:layout_width="100px"
android:layout_height="wrap_content"
android:text=" Ok "
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:layout_below="#+id/image"
/>
</RelativeLayout>
Then, Where you want to place the Alert, Do like below
final Dialog dialog = new Dialog(context);
dialog.setContentView(R.layout.dialog);
dialog.setTitle("Your Title");
TextView text = (TextView) dialog.findViewById(R.id.text);
text.setText("Text");
ImageView image = (ImageView) dialog.findViewById(R.id.image);
image.setImageResource(R.drawable.ic_launcher);
Button dialogButton = (Button) dialog.findViewById(R.id.dialogButtonOK);
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
dialog.dismiss();
}
});
dialog.show();

How to place 2 buttons at the same position in my layout

I have My Table row like below in my xml layout:
<TableRow
android:layout_marginTop="10dp"
>
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="256dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/titlename"
android:layout_="#+id/playbtn"
android:layout_marginTop="4dp"
/>
<Button
android:id="#+id/playbtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:background="#drawable/play"
android:layout_marginBottom="3dp"/>
<Button
android:id="#+id/pausebtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:layout_toTopOf="#+id/playbtn"
android:layout_alignParentBottom="true"
android:background="#drawable/pause"
android:layout_marginBottom="3dp"/>
</TableRow>
and my output is as below,
my requirement is to show play pause buttons at the same position in my layout?
Could any one help?
Use FrameLayout and put one button over another
Like this
<FrameLayout ... >
<Button
android:id="#+id/playbtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/play"/>
<Button
android:id="#+id/pausebtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/pause"/>
</FrameLayout>
This will put Pause button over Play Button. Make the necessary button visible and invisible according to your need
Try using this layout. Use combination of LinearLayout and FrameLayout to achieve the desired result.
<TableRow
android:layout_marginTop="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weight="1"
android:layout_alignLeft="#+id/titlename"
android:layout_="#+id/playbtn"
android:layout_marginTop="4dp"
/>
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<Button
android:id="#+id/playbtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/play"/>
<Button
android:id="#+id/pausebtn"
android:layout_width="40dp"
android:layout_height="40dp"
android:background="#drawable/pause"/>
</FrameLayout>
</LinearLayout>
</TableRow>
once Try this:
<TableRow
android:id="#+id/tableRow1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" >
<SeekBar
android:id="#+id/seekBar1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".8" />
<Button
android:id="#+id/play"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
/>
</TableRow>
Main Activity
private boolean playing = false;
Button play;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
play=(Button) findViewById(R.id.play);
play.setBackgroundResource(R.drawable.pause);
play.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
if(playing){
playing = false;
play.setBackgroundResource(R.drawable.pause);
}
else {
playing = true;
play.setBackgroundResource(R.drawable.play);
}
}
});
}
Why can't you try merge?
Have a glance of this.
http://android-developers.blogspot.in/2009/03/android-layout-tricks-3-optimize-by.html
You don't need to create two buttons for it. You can do it with single. I have created a sample program. I find this to be a cleaner approach.
Layout for MainActivity
<LinearLayout 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"
android:gravity="center">
<Button
android:id="#+id/buttonPlayPause"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
Here is MainActivity
package in.live.homam.imagebuttonexample;
import android.app.Activity;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
private Button buttonPlayPause;
private static final int resourceIdPlay = R.drawable.play;
private static final int resourceIdPause = R.drawable.pause;
private int resourceIdButton = resourceIdPlay;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
buttonPlayPause = (Button) findViewById(R.id.buttonPlayPause);
buttonPlayPause.setBackgroundResource(resourceIdButton);
buttonPlayPause.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if(resourceIdButton == resourceIdPlay) {
resourceIdButton = resourceIdPause;
Log.d("Tag", "Playing");
}
else {
resourceIdButton = resourceIdPlay;
Log.d("Tag", "Paused");
}
buttonPlayPause.setBackgroundResource(resourceIdButton);
}
});
}
}

Categories

Resources