How to make this kind of tab in Android [http://i.stack.imgur.com/rIbUX.png]
just mention that see the overlap area, when you click on of the tab, the overlap changed.
here is one chinese version example in which I think that's what I want to have, but they don't provide the complete code, and I have no idea how to go on this project.
http://www.oschina.net/question/54100_29061
I am currently using Android 3.2 and ICS 4+ to implement this project, so welcome if that's possible to implement competible with Framgment.
I finally I made the solution by myself. I just leave the native tab host implementation, make up my own.
here is the screen shot:
[http://i.stack.imgur.com/1mXLZ.png]
here is the Activity code:
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
public class PelesysTabHostActivity extends Activity {
private ImageView ib1, ib2, ib3, last;
private Drawable pressed, released;
private TextView tv,tv1,tv2,tv3;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ib1 = (ImageView) this.findViewById(R.id.imageView1);
ib2 = (ImageView) this.findViewById(R.id.imageView2);
ib3 = (ImageView) this.findViewById(R.id.imageView3);
tv = (TextView) this.findViewById(R.id.textView1);
tv1= (TextView) this.findViewById(R.id.textView11);
tv2= (TextView) this.findViewById(R.id.textView22);
tv3= (TextView) this.findViewById(R.id.textView33);
pressed = getResources().getDrawable(R.drawable.ui_table_tab_button);
released = getResources().getDrawable(
R.drawable.ui_table_tab_button_disabled);
ib1.setImageDrawable(pressed);
last = ib1;
ib1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
last.setImageDrawable(released);
ib1.setImageDrawable(pressed);
last = ib1;
tv.setText("I am super 1");
ib1.bringToFront();
tv1.bringToFront();
}
});
ib2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
last.setImageDrawable(released);
ib2.setImageDrawable(pressed);
last = ib2;
tv.setText("TWO!!! I am super 2");
ib2.bringToFront();
tv2.bringToFront();
}
});
ib3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
last.setImageDrawable(released);
ib3.setImageDrawable(pressed);
last = ib3;
tv.setText(" III !!! I am super 3");
ib3.bringToFront();
tv3.bringToFront();
}
});
}
}
here is the layout file I used (main.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" >
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="330dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" >
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/ui_table_bg_coursedetail" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/relativeLayout2"
android:layout_alignParentLeft="true"
android:layout_marginLeft="326dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/ui_table_tab_button_disabled" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="90dp"
android:src="#drawable/ui_table_tab_button_disabled" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="180dp"
android:src="#drawable/ui_table_tab_button_disabled" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView1"
android:layout_marginLeft="50dp"
android:text="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
<TextView
android:id="#+id/textView22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView2"
android:layout_marginLeft="50dp"
android:text="2"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
<TextView
android:id="#+id/textView33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView3"
android:layout_marginLeft="50dp"
android:text="3"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
</RelativeLayout>
Just a week now I used this : https://github.com/AdilSoomro/Iphone-Tab-in-Android
Very well worked! You can customize it as its in your first picture
Related
It is showing cannot resovle R.
how i can solve this problem?????
if you need xml file to solve problem ,ask me in comment
Please help
..................................................................................................................................................................................................................................................................................................................
Here's the java code:
package com.example.android.justjava;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import java.text.NumberFormat;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
int quantity = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
int price= quantity*16;
String priceMessage="total:" + (quantity*16) ;
priceMessage=priceMessage +"\nThank You!";
displayMessage(priceMessage);
}
/**
* This method displays the given text on the screen.
*/
private void displayMessage(String message) {
TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
priceTextView.setText(message);
}
public void increase(View view) {
quantity = quantity + 1;
displayPrice(quantity*16);
display(quantity);
}
public void decrease(View view) {
quantity = quantity - 1;
displayPrice(quantity*16);
display(quantity);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
/**
* This method displays the given price on the screen.
*/
private void displayPrice(int number) {
TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number);
}
here's the xml file:::
................................................................................................................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/w"
android:orientation="vertical"
>
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="Welcome to Ordering Menu"
android:textColor="#android:color/white"
android:textSize="25sp"
app:fontFamily="#font/crafty_girls" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="20dp"
android:src="#drawable/cappo"/>
<Button
android:id="#+id/btn2"
android:layout_width="48dp"
android:layout_height="48dp"
android:textSize="30sp"
android:layout_marginLeft="50dp"
android:layout_marginTop="20dp"
android:onClick="increase"
android:text="+"
android:textColor="#android:color/black"
android:background="#android:color/white" />
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:text="0"
android:textSize="20sp"
android:textColor="#android:color/white" />
<Button
android:id="#+id/btn3"
android:layout_width="50dp"
android:textColor="#android:color/black"
android:background="#android:color/white"
android:layout_height="50dp"
android:textBold="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:onClick="decrease"
android:textSize="30sp"
android:text="-" />
</LinearLayout>
<TextView
android:id="#+id/kk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="170dp"
android:text="Price" />
<TextView
android:id="#+id/price_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:text="$0"
android:textColor="#000000" />
<Button
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:onClick="submitOrder"
android:text="ORDER" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
This may not be the case for you but worth a shot, sometimes Android studio is glitchy and needs to be closed/ reopened. Also you could try, Build > Clean Project.
Try from android studio menu File -> Invalidate Caches and Restart -> Invalidate and Restart
i'm new in this type of developing ,so can i know where can i find this import list
So i can suggest you to check few things.
Make sure you have installed your targeted build tools. Eg: API 28
Check the package name in your AndroidManifest.xml file. You may have deleted the package name from the manifest file mistakenly.
If none of the above in your case, try to import com.example.android.justjava.R
I am creating a diet app for myself and I do not know how to transfer result from one calculation which was done in a different activity and use it in another one.
To make things more complicated, I want my spinner in MoreLooseWeightDetails.class to have a list of different diet types which have different fat, proteins and carb ratio. Every time the user choose different type it should automatically change the ratio.
This is where the calculation is being done and has to be trnasfered to MoreLooseWeightDetails.class
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
public class LooseWeight extends AppCompatActivity {
TextView TotalCal;
EditText numb2;
Spinner ActLvl;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loose_weight);
numb2 = (EditText) findViewById(R.id.value1);
ActLvl = (Spinner) findViewById(R.id.value2);
TotalCal = (TextView)findViewById(R.id.resultDisplay);
final Spinner ActLvl = (Spinner)findViewById(R.id.value2);
ArrayAdapter<String> myAdapter = new ArrayAdapter<>(LooseWeight.this, android.R.layout.simple_expandable_list_item_1,getResources().getStringArray(R.array.lvl));
myAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ActLvl.setAdapter(myAdapter);
Button calcBtn = (Button)findViewById(R.id.result);
calcBtn.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick (View view) {
float numb3 = Float.parseFloat(numb2.getText().toString());
float a = numb3 * 24;
float b = a * Float.parseFloat(ActLvl.getSelectedItem().toString());
float c = b - 500;
TotalCal.setText(Float.toString(c));
}
});
Button extra = (Button)findViewById(R.id.advance);
extra.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(),MoreLooseWeightDetails.class);
startActivity(intent);
}
});
}
}
Here is the MoreLooseWeightDetails.class
package com.fitup.fit_up;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MoreLooseWeightDetails extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_more_loose_weight_details);
}
}
Here is the MoreLooseWeightDetails.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/activity_more_loose_weight_details"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.fitup.fit_up.MoreLooseWeightDetails">
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="#+id/Title3"
tools:text="More"
android:textSize="36sp" />
<TextView
android:text="Select Type of Diet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/Title3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="19dp"
android:id="#+id/Info3"
android:textSize="30sp" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/Info3"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:id="#+id/spinner" />
<TextView
android:text="You Should Eat :"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:id="#+id/Info4"
android:textSize="30sp"
android:layout_below="#+id/spinner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text="Protein (grams):"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/unit1"
android:textSize="24sp"
android:layout_below="#+id/Info4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="78dp" />
<TextView
android:text="Fat (grams):"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/unit3"
android:textSize="24sp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/unit3"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/result1"
android:textSize="30sp"
android:textAlignment="center"
android:layout_alignLeft="#+id/result2"
android:layout_alignStart="#+id/result2" />
<TextView
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/unit2"
android:id="#+id/result2"
android:textSize="30sp"
android:textAlignment="center"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="#+id/result3"
android:layout_alignStart="#+id/result3" />
<TextView
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/unit2"
android:id="#+id/result3"
android:textSize="30sp"
android:textAlignment="center"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="#+id/unit2"
android:layout_toEndOf="#+id/unit2" />
<TextView
android:text="Carbohydrates (grams):"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="43dp"
android:id="#+id/unit2"
android:textSize="24sp"
android:layout_below="#+id/unit1"
android:layout_alignRight="#+id/unit1"
android:layout_alignEnd="#+id/unit1" />
</RelativeLayout>
I'm making a cooking application and I have created a favourite button that seems to work ok i click on it and it changes colour. I tried to create a toast where when I click on the button a message wil come up to say
added to favourites
and
removed from favourites
the code I have used for the toast doesn't have an errors and the application runs perfectly but the toast does not appear
here is my code that I have used
Toast.java
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.CheckBox;
import android.widget.Toast;
public class Favourite_Toast extends Activity {
private CheckBox fav;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.recipe);
addListenerOnChk();
}
public void addListenerOnChk() {
fav = (CheckBox) findViewById(R.id.checkBox);
fav.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (((CheckBox) v).isChecked()) {
Toast.makeText(Favourite_Toast.this,
"Added to Favourites", Toast.LENGTH_LONG).show();
}
}
});
}
}
favourite.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true"
android:drawable="#drawable/heart_red" />
<item android:state_checked="false"
android:drawable="#drawable/heart_grey" />
</selector>
recipe.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/jbsbackground2"
android:orientation="vertical" >
<ImageView
android:id="#+id/iv_detail"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:scaleType="centerCrop"
android:src="#drawable/barbecuedporkribs" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="10dp"
android:layout_below="#+id/iv_detail"
android:background="#3D3C3A" />
<ScrollView
android:id="#+id/scrollView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/button1" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_below="#+id/scrollView1"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="5dp"
android:text="#string/textView2"
android:layout_toLeftOf="#id/favourites"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:id="#+id/tvName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tvName"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="italic"
android:layout_below="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/checkBox"
android:button="#drawable/favourite"
android:checked="false"
android:layout_alignTop="#+id/textView2"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="46dp"
android:layout_marginEnd="46dp"
android:clickable="true" />
<TextView
android:id="#+id/tvTD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/tvTD"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold"
android:layout_below="#+id/checkBox"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:id="#+id/tvIngredients"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvTD"
android:layout_marginTop="2dp"
android:text="#string/tvIngredients"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="italic" />
<TextView
android:id="#+id/tvK"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvIngredients"
android:layout_marginTop="5dp"
android:text="#string/tvK"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textStyle="bold" />
<TextView
android:id="#+id/tvPreparation"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/tvK"
android:layout_marginTop="2dp"
android:text="#string/tvPreparation"
android:textColor="#000000"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textStyle="italic" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
I've used a checkbox for the favourite button could that be the reason why the toast is not working
Also would anyone be able to tell me how to make the code so that once you have clicked on the favourite button it will stay clicked, because as it is it does not stay clicked on
Thanks in advance
I recommend you change your OnClickListener with OnCheckedChangeListener. It will get invoked when the user checks / unchecks the state of the CheckBox. IMHO, it's the better listener for this widget.
Try the code below
if ((fav.isChecked()) {
Toast.makeText(Favourite_Toast.this, "Added to Favourites", Toast.LENGTH_LONG).show();
}
else{
Toast.makeText(Favourite_Toast.this, "Removed From Favourites", Toast.LENGTH_LONG).show();
}
Use this code in MainActivity... THIS WILL SOLVE YOUR PROBLEM:
public class MainActivity extends Activity {
private CheckBox chk;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
chk = (CheckBox) findViewById(R.id.checkBox1);
chk.setOnClickListener(checkboxClickListener);
}
View.OnClickListener checkboxClickListener = new View.OnClickListener() {
#Override
public void onClick(View view) {
boolean checked = ((CheckBox) view).isChecked();
if (checked) {
Toast.makeText(MainActivity.this,"Added to favourite", Toast.LENGTH_LONG).show();
}
else {
Toast.makeText(MainActivity.this,"Removed from favourite", Toast.LENGTH_LONG).show();
}
}
};
}
I created an application, my first, and am having problems running it on an AVD. Won't load the first activity, just says 'Unfortunately, FussyFestivalrV7 has stopped. This is the main starting activity:
package com.example.fussyfestivalr;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Button switchButton = (Button) findViewById(R.id.button1);
switchButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MainActivity.this, News.class);
startActivity(intent);
}
});
}
}
And my layout
<RelativeLayout 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:background="#string/title"
tools:context="${relativePackage}.${activityClass}" >
<TextView
android:id="#+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/title"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/newsbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/title"
android:layout_centerHorizontal="true"
android:layout_marginTop="35dp"
android:text="#string/news" />
<Button
android:id="#+id/exit"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="17dp"
android:layout_toRightOf="#+id/title"
android:text="#string/exit" />
<Button
android:id="#+id/bands"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/exit"
android:layout_centerHorizontal="true"
android:layout_marginBottom="44dp"
android:text="#string/bands" />
<Button
android:id="#+id/fafq"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/bands"
android:layout_centerHorizontal="true"
android:layout_marginBottom="53dp"
android:text="#string/fafq" />
<Button
android:id="#+id/profiles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/fafq"
android:layout_centerHorizontal="true"
android:layout_marginBottom="41dp"
android:text="#string/festivals" />
Check whether you have </RelativeLayout>.
I hope to help.
Paul.
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);
}
});
}
}