I need to place two ImageButtons on top of each other something like the following image.
While placing them has been no issue, I am unable to click the blue button. The red button when clicked works perfectly well.
The XML layout code is as follows:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1" >
<ImageButton
android:id="#+id/bluebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:onClick="onButtonClicked"
android:scaleType="fitCenter"
android:src="#drawable/bluebutton" />
<ImageButton
android:id="#+id/redbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:onClick="onButtonClicked"
android:scaleType="fitCenter"
android:src="#drawable/redbutton" />
</FrameLayout>
How do i ensure that both buttons can be clicked ?
You can simply use a RelativeLayout to do that. See this I made just now:
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageButton btn = (ImageButton)findViewById(R.id.bluebutton);
ImageButton btn2 = (ImageButton)findViewById(R.id.redbutton);
btn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView t = (TextView)findViewById(R.id.txt);
t.setText("Hello!");
}
});
btn2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
TextView t = (TextView)findViewById(R.id.txt);
t.setText("Hi, how are you?");
}
});
}
it's just an example
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center">
<ImageButton
android:background="#ff040ab2"
android:id="#+id/bluebutton"
android:layout_width="150dp"
android:layout_height="250dp"
android:onClick="onButtonClicked"
android:scaleType="fitCenter"/>
<ImageButton
android:rotation="90"
android:background="#be2222"
android:id="#+id/redbutton"
android:layout_width="150dp"
android:layout_height="250dp"
android:onClick="onButtonClicked"
android:scaleType="fitCenter"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/txt"
android:textColor="#ffffff"/>
</RelativeLayout>
Changed the code.
public class MainActivity extends Activity {
ImageButton red,blue;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
red = (ImageButton)findViewById(R.id.redbutton);
blue = (ImageButton)findViewById(R.id.bluebutton);
}
public void onRedButtonClicked(final View view) {
Toast.makeText(getApplicationContext(), "Button red is clicked!", Toast.LENGTH_SHORT).show();
}
public void onBlueButtonClicked(final View view) {
Toast.makeText(getApplicationContext(), "Button blue is clicked!", Toast.LENGTH_SHORT).show();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}
And the layout:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android: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=".MainActivity" >
<ImageButton
android:id="#+id/redbutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:onClick="onRedButtonClicked"
android:scaleType="fitCenter"
android:src="#drawable/redbutton"
android:visibility="visible"/>
<ImageButton
android:id="#+id/bluebutton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#null"
android:onClick="onBlueButtonClicked"
android:scaleType="fitCenter"
android:src="#drawable/bluebutton"
android:visibility="visible"/>
</FrameLayout>
Hope this helps..:)
Related
I am using SwipeLayout in my activity.
Activity is having 2 buttons. On button click, I want to set respective fragment on bottom layout and swipe view programmatically. And on close, it should set replace bottom layout with default fragment so that on swipe it displays default fragment.
When I set default fragment in onClose method of swipeLayout's addSwipeListener, it does not listen to button click.
This works fine with RecyclerView but now I want same in activity
XML
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
android:id="#+id/card_view"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
card_view:cardBackgroundColor="#android:color/white"
card_view:cardCornerRadius="6dp"
card_view:cardElevation="6dp"
xmlns:swipe="http://schemas.android.com/tools">
<com.daimajia.swipe.SwipeLayout
android:id="#+id/swipe_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- Bottom View Start-->
<!--What you want to show-->
<LinearLayout
android:id="#+id/sub_item_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#android:color/holo_orange_light">
</LinearLayout>
<!-- Bottom View End-->
<!-- Surface View Start -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:id="#+id/frame_list_card_item"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="9"
android:background="#eefeef"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="#+id/title_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="this is the Title this is the Title this is the Title this is the Title this is the Title "
android:textColor="#000"
android:textSize="15sp"/>
<LinearLayout
android:id="#+id/container_list_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="this is description text this is description text this is description text this is description text this is description text this is description text this is description text this is description text this is description text this is description text this is description text "
android:textSize="13sp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<Button
android:id="#+id/btn_one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:text="4"/>
<Button
android:id="#+id/btn_two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:minHeight="0dp"
android:text="5"/>
</LinearLayout>
</LinearLayout>
<!--What you want to show in SurfaceView-->
</LinearLayout>
</LinearLayout>
<!-- Surface View End -->
</com.daimajia.swipe.SwipeLayout>
</android.support.v7.widget.CardView>
JAVA
package com.sp.spsamples3.activities;
public class SwipeLayoutActivity extends AppCompatActivity {
SwipeLayout mSwipeLayout;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_swipe_layout);
mSwipeLayout = (SwipeLayout) findViewById(R.id.swipe_layout);
getSupportFragmentManager().beginTransaction().replace(R.id.sub_item_container, new DefaultFragment()).commit();
mSwipeLayout.setShowMode(SwipeLayout.ShowMode.LayDown);
mSwipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
#Override
public void onStartOpen(SwipeLayout layout) {
}
#Override
public void onOpen(SwipeLayout layout) {
}
#Override
public void onStartClose(SwipeLayout layout) {
}
#Override
public void onClose(SwipeLayout layout) {
getSupportFragmentManager().beginTransaction().replace(R.id.sub_item_container, new DefaultFragment()).commit();
}
#Override
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
}
#Override
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
}
});
initClicks();
}
private void initClicks() {
((Button) findViewById(R.id.btn_one)).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.i("sp testing", "1 clicked");
setFragment(new ScreenOneFragment());
mSwipeLayout.open(true);
}
});
((Button) findViewById(R.id.btn_two)).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.i("sp testing", "2 clicked");
setFragment(new ScreenTwoFragment());
mSwipeLayout.open(true);
}
});
}
private void setFragment(Fragment fragment) {
getSupportFragmentManager().beginTransaction().replace(R.id.sub_item_container, fragment).commit();
}
}
i want to hide my keypad while keypad collapse image clicks and animate my dialPad enter number relative layout to upside of bottom call layout
But i want to animate my enter number edittext layout to place up on bottom layout, please anyone help me.
This is my code
public class MainActivity extends ActionBarActivity {
private GridView gridView;
private TextView grid_num_tv;
private EditText phone_num_edt;
private RelativeLayout gridView_collapse_rl, dialPad_overflow_rl, dialPad_num_edt_rl;
private ImageView dialPad_collapse_iv;
static final String[] GRID_NUM = new String[] {
"1", "2", "3",
"4", "5", "6",
"7" ,"8", "9" ,
"*", "0", "#"};
static final String[] GRID_LETTERS = new String[] {
" ", "abc", "def",
"ghi", "jkl", "mno",
"pqrs" ,"tuv", "wxyz" ,
" ", "+", " "};
Context context;
ArrayList<GridListDataModel> myGridList = new ArrayList<GridListDataModel>();
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
gridView = (GridView) findViewById(R.id.gridView1);
phone_num_edt = (EditText) findViewById(R.id.dial_pad_num_editText);
gridView_collapse_rl = (RelativeLayout) findViewById(R.id.dial_close_rl);
dialPad_overflow_rl = (RelativeLayout) findViewById(R.id.dial_overflow_rl);
dialPad_collapse_iv = (ImageView) findViewById(R.id.dialpad_collapse_imageView);
dialPad_num_edt_rl = (RelativeLayout) findViewById(R.id.dial_num_edt_rl);
gridView.setVisibility(View.VISIBLE);
gridView.setAdapter(new CustomGridAdapter(this, GRID_NUM));
gridView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
grid_num_tv = (TextView) view.findViewById(R.id.grid_num_textView);
Toast.makeText(getApplicationContext(), grid_num_tv.getText(), Toast.LENGTH_SHORT).show();
}
});
gridView_collapse_rl.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(gridView.isShown()){
dialPad_collapse_iv.setImageResource(R.drawable.ic_action_collapse);
gridView.setVisibility(View.INVISIBLE);
}else{
dialPad_collapse_iv.setImageResource(R.drawable.ic_action_expand);
gridView.setVisibility(View.VISIBLE);
}
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
activity_main.xml is my main layout xml file
<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: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.example.gridviewdemo.MainActivity" >
<RelativeLayout
android:id="#+id/dialpad_bottom_rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true" >
<RelativeLayout
android:layout_width="60dp"
android:layout_height="45dp"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:layout_marginBottom="10dp"
android:layout_toLeftOf="#+id/dial_overflow_rl"
android:layout_toRightOf="#+id/dial_close_rl"
android:background="#android:color/holo_green_light" >
<ImageView
android:id="#+id/dialpad_call_imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#android:drawable/ic_menu_call" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/dial_close_rl"
android:layout_width="60dp"
android:layout_height="45dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="#+id/dialpad_collapse_imageView"
android:layout_width="25dp"
android:layout_height="25dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_action_expand" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/dial_overflow_rl"
android:layout_width="60dp"
android:layout_height="45dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true" >
<ImageView
android:id="#+id/dialpad_overflow_imageView"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:src="#drawable/ic_action_overflow" />
</RelativeLayout>
</RelativeLayout>
<GridView
android:id="#+id/gridView1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/dialpad_bottom_rl"
android:gravity="center"
android:numColumns="3" >
</GridView>
<RelativeLayout
android:id="#+id/dial_num_edt_rl"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/gridView1"
android:layout_above="#+id/gridView1"
android:layout_marginBottom="20dp"
android:layout_marginTop="189dp" >
<EditText
android:id="#+id/dial_pad_num_editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/backspace_imageView"
android:ems="10"
android:hint="Enter number" >
<requestFocus />
</EditText>
<ImageView
android:id="#+id/backspace_imageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="15dp"
android:src="#drawable/ic_action_backspace" />
</RelativeLayout>
</RelativeLayout>
grid_item.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="#+id/grid_num_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="22dp"
android:text="2"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000"
android:textSize="30dp" />
<TextView
android:id="#+id/grid_letter_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/grid_num_textView"
android:paddingLeft="5dp"
android:text="abc"
android:textAppearance="?android:attr/textAppearanceSmall" />
</RelativeLayout>
</RelativeLayout>
I don't know what exactly your layout was, so i write an example here, hope it can help you.
The key here is android:animateLayoutChanges="true" in your container layout.
I assume that your "enter number" is my tv_b, and the keypad is tv_a.
Here is the layout:
activity_test.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:animateLayoutChanges="true"
android:orientation="vertical">
<Button
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:id="#+id/btn_animate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Animate" />
<TextView
android:id="#+id/tv_a"
android:layout_centerHorizontal="true"
android:layout_above="#+id/btn_animate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABCCC" />
<TextView
android:id="#+id/tv_b"
android:layout_above="#+id/tv_a"
android:layout_centerHorizontal="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ABCCD" />
</RelativeLayout>
And activity code:
MainActivity.java
public class MainActivity extends FragmentActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
Button btnAnimate = (Button) findViewById(R.id.btn_animate);
final TextView tva = (TextView) findViewById(R.id.tv_a);
final TextView tvb = (TextView) findViewById(R.id.tv_b);
btnAnimate.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (tva.getVisibility() == View.VISIBLE) {
tva.setVisibility(View.GONE);
} else {
tva.setVisibility(View.VISIBLE);
}
}
});
}
}
You will see animation when click button Animate.
res/anim/scale.xml
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" >
<scale
android:duration="500"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="100%"
android:pivotY="100%"
android:toXScale="1.0"
android:toYScale="0.0" />
</set>
use this scale animation for that layout on button click as below:
Animation animation=AnimationUtils.loadAnimation(activity, R.anim.scale);
animation.setFillAfter(true);
gridView.startAnimation(animation);
I have a textview in dialog and I want when I click this textview to do something.
I want it when clicking on the textview to do something.
I have added clickable and onClick in my layout
Here are my codes
public class Activitytwo extends ActionBarActivity {
#Override
public void onCreate(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//WORKING CODES
//WORKING CODES
//WORKING CODES
//WORKING CODES
}
// This one to show the dialog
//This one works fine!
public void share(View view){
sharedialog = new Dialog(Activitytwo.this);
sharedialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
sharedialog.setContentView(R.layout.postdialog);
sharedialog.setCanceledOnTouchOutside(true);
sharedialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
sharedialog.show();
}
public void facebookp(View view){
//This one for the TextView (onClick)
//This one doesn't work..
}
}
This is my layout (postdialog.xml)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:ads="http://schemas.android.com/apk/res-auto"
android:id="#+id/postdialogl"
android:layout_width="match_parent"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_height="150dp"
android:background="#drawable/postdialog" >
<TextView
android:id="#+id/postdtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="20dp"
android:textSize="18sp"
android:textStyle="bold"
android:text="#string/post"
android:textColor="#a7b8d6"/>
<ImageView
android:id="#+id/poststrokea"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#202e4c"
android:layout_below="#+id/postdtitle"
android:layout_marginTop="5dp"/>
<ImageView
android:id="#+id/poststrokeb"
android:layout_width="match_parent"
android:layout_height="0.5dp"
android:background="#803e5482"
android:layout_below="#+id/poststrokea"/>
<TextView
android:id="#+id/facebookpost"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_marginTop="60dp"
android:layout_marginLeft="30dp"
android:drawablePadding="5dp"
android:text="#string/facebook"
android:textColor="#a7b8d6"
android:textSize="12sp"
android:drawableTop="#drawable/facebook"
android:clickable="true"
android:onClick="facebookp"/>
</RelativeLayout>
One solution is to declare your textview inside your dialog.
public void share(View view){
//your code.
sharedialog = new Dialog(Activitytwo.this);
sharedialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
sharedialog.setContentView(R.layout.postdialog);
sharedialog.setCanceledOnTouchOutside(true);
sharedialog.getWindow().setBackgroundDrawable(newColorDrawable(android.graphics.Color.TRANSPARENT));
final TextView tviPost = (TextView) sharedialog.findViewById(R.id.sharedialog);
tviPost.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
//Do something
}
});
sharedialog.show();
}
and delete the next lines from your layout.
android:clickable="true"
android:onClick="facebookp"
I am using Vuforia AR sdk and want to create a button on the camera preview on the screen.
I cannot figure out where and how to add the button.
I have edit the camera_overlay_udt.xml like this.. In my layout design i have placed back button and listview.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:id="#+id/headerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="#drawable/header"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/backButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:background="#android:color/transparent"
android:src="#drawable/back" />
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Swipart"
android:textColor="#color/white"
android:textSize="18dp"
android:textStyle="bold" />
<ImageButton
android:id="#+id/arcstarButton"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_centerInParent="true"
android:layout_marginRight="10dp"
android:background="#android:color/transparent"
android:src="#drawable/star_button" />
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/favListingLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/headerLayout"
android:gravity="top"
android:orientation="horizontal"
android:visibility="visible" >
<ListView
android:id="#+id/favlist"
android:layout_width="120dp"
android:layout_height="match_parent"
android:layout_marginBottom="50dp"
android:layout_marginLeft="7dp"
android:cacheColorHint="#00000000" />
</LinearLayout>
<LinearLayout
android:id="#+id/bottom_bar"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="#color/overlay_bottom_bar_background"
android:gravity="center_vertical"
android:orientation="horizontal"
android:visibility="visible"
android:weightSum="1" >
<View
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#color/overlay_bottom_bar_separators" />
<ImageButton
android:id="#+id/camera_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#null"
android:contentDescription="#string/content_desc_camera_button"
android:onClick="onCameraClick"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:src="#drawable/camera_button_background" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#id/bottom_bar"
android:background="#color/overlay_bottom_bar_separators" />
</RelativeLayout>
after that please Edit that ImageTargets.java class
private void addOverlayView(boolean initLayout) {
// Inflates the Overlay Layout to be displayed above the Camera View
LayoutInflater inflater = LayoutInflater.from(this);
mUILayouts = (RelativeLayout) inflater.inflate(
R.layout.camera_overlay_udt, null, false);
mUILayouts.setVisibility(View.VISIBLE);
// If this is the first time that the application runs then the
// uiLayout background is set to BLACK color, will be set to
// transparent once the SDK is initialized and camera ready to draw
if (initLayout) {
mUILayouts.setBackgroundColor(Color.TRANSPARENT);
}
// Adds the inflated layout to the view
addContentView(mUILayouts, new LayoutParams(LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT));
// Gets a reference to the bottom navigation bar
mBottomBar = mUILayouts.findViewById(R.id.bottom_bar);
// Gets a reference to the Camera button
mCameraButton = mUILayouts.findViewById(R.id.camera_button);
mCameraButton.setVisibility(View.GONE);
favButton = (ImageButton) mUILayouts.findViewById(R.id.arcstarButton);
listview = (ListView) mUILayouts.findViewById(R.id.favlist);
backButton = (ImageButton) mUILayouts.findViewById(R.id.backButton);
backButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View paramView) {
// TODO Auto-generated method stub
finish();
}
});
listview.setVisibility(View.GONE);
galleryList = SendFile.getFavourites();
if (galleryList != null) {
gridviewAdapter = new GridviewAdapter(ImageTargets.this);
listview.setAdapter(gridviewAdapter);
}
favButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (galleryList != null && galleryList.size() > 0) {
if (listview.getVisibility() == View.GONE) {
listview.setVisibility(View.VISIBLE);
} else {
listview.setVisibility(View.GONE);
}
} else {
Toast.makeText(ImageTargets.this, "Favourites not fond",
Toast.LENGTH_LONG).show();
}
}
});
listview.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> paramAdapterView,
View paramView, int positon, long paramLong) {
SendFile.setFavourite(galleryList.get(positon));
Intent intent = new Intent(ImageTargets.this,
LoadingScreen.class);
Bundle bundle = new Bundle();
bundle.putInt("x", x_Axis);
bundle.putInt("y", y_Axis);
intent.putExtras(bundle);
startActivity(intent);
finish();
}
});
showDialogHandler = new Handler() {
public void handleMessage(Message msg) {
String aResponse = msg.getData().getString("message");
if ((null != aResponse)) {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),
"Server Response: " + aResponse, Toast.LENGTH_SHORT)
.show();
showAlertDialog(aResponse);
} else {
// ALERT MESSAGE
Toast.makeText(getBaseContext(),
"Not Got Response From Server.", Toast.LENGTH_SHORT)
.show();
}
};
};
loadingDialogHandler.captureButtonContainer = mUILayouts
.findViewById(R.id.camera_button);
mUILayouts.bringToFront();
}
They showing there layouts using handlers
Start you camera preview in a normal way. Place a layout on top of it with transparent background like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:background="#ff000000"
android:layout_height="match_parent">
<ImageView
android:id="#+id/start_image_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="5dp"
android:scaleType="fitXY"
android:layout_weight="1"
android:src="#drawable/scan_image"/>
</RelativeLayout>
In java file, you can add this layout like this:
private View mStartupView;
mStartupView = getLayoutInflater().inflate(
R.layout.startup_screen, null);
// Add it to the content view:
addContentView(mStartupView, new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT));
This way you will get to see your button on top of camera preview. Hope it helps
You can add buttons in cameraoverlay layout which is in layout folder and you can initialize buttons in initAR function which is in mainactivity.
Step 1: Add the button in the camera_overlay.xml
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/camera_overlay_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ProgressBar
style="#android:style/Widget.ProgressBar"
android:id="#+id/loading_indicator"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="18dp"
android:layout_marginTop="51dp"
android:text="Button" />
</RelativeLayout>
Step 2: Edit the ImageTargets.java class
private static final String LOGTAG = "ImageTargets";
private Button b1;
Step 3: Modify the initApplicationAR() function of ImageTargets.java class
private void initApplicationAR()
{
// Create OpenGL ES view:
int depthSize = 16;
int stencilSize = 0;
boolean translucent = Vuforia.requiresAlpha();
mGlView = new SampleApplicationGLView(this);
mGlView.init(translucent, depthSize, stencilSize);
mRenderer = new ImageTargetRenderer(this, vuforiaAppSession);
mRenderer.setTextures(mTextures);
mGlView.setRenderer(mRenderer);
b1 = (Button) findViewById(R.id.button1);
b1.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
b1.setVisibility(View.GONE);
}
});
}
Now lay back and watch your button disappear on a click!
Although it's a long time since the post.. yet I found one article.. wherein you can have the desired thing..
Ref: https://medium.com/nosort/adding-views-on-top-of-unityplayer-in-unityplayeractivity-e76240799c82
Solution:
Step1: Make a custom layout XML file (vuforia_widget_screen.xml). For example, button has been added.
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/main_layout">
<FrameLayout
android:id="#+id/unity_player_layout"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<Button
android:id="#+id/back_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:background="#null"
android:text="#string/welcome" />
</FrameLayout>
Step 2: Make following changes in the UnityPlayerActivity.java
Replace "setContentView(mUnityPlayer);" with
setContentView(R.layout.vuforia_widget_screen);
FrameLayout frameLayout = findViewById(R.id.unity_player_layout);
frameLayout.addView(mUnityPlayer.getView());
-> For anyone, who will face the issue in future. :)
I have an app, which shows toast below the actionbar. I'm using Crouton library for displaying toast. Here I'm placing custom layout for toast, that layout contains one textview and one button (for close option). So Toast appears with button. If I click that it should close the toast but nothing happens.. Below Code for this example. Any Help Appreciated
MainActivity.java
public class MainActivity extends SherlockActivity implements OnClickListener {
private View customToastView;
private TextView customToastMessageView;
private Button customToastCloseButton;
private Button doneButton;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
doneButton = (Button) findViewById(R.id.done_button);
customToastView = getLayoutInflater().inflate(R.layout.toast_custom_layout, null);
customToastMessageView = (TextView) customToastView.findViewById(R.id.messages);
customToastCloseButton = (Button) customToastView.findViewById(R.id.close_button);
customToastCloseButton.setOnClickListener(this);
doneButton.setOnClickListener(this);
}
#Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.done_button:
Crouton.cancelAllCroutons();
customToastMessageView.setText("Message");
Crouton.show(this, customToastView);
break;
case R.id.close_button:
Crouton.cancelAllCroutons();
break;
}
}
}
toast_custom_layout.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" >
<TextView
android:id="#+id/messages"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="26dp"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Button
android:id="#+id/close_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="23dp"
android:text="Button" />
</RelativeLayout>
activity_main.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="#+id/done_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="146dp"
android:text="Button" />
</RelativeLayout>