I have a numberpicker dialog to select hours and minutes (15 minutes interval). It works fine on large screens but on small screens and older devices it gets stuck if I try to scroll using touch.
I am extending the android.widget.NumberPicker and reducing the font size which helps on some devices.
public class TimerNumberPicker extends android.widget.NumberPicker {
public TimerNumberPicker(Context context) {
super(context);
}
public TimerNumberPicker(Context context, AttributeSet attrs){
super(context,attrs);
}
#Override
public void addView(View child) {
super.addView(child);
updateView(child);
}
#Override
public void addView(View child, ViewGroup.LayoutParams params) {
super.addView(child, params);
updateView(child);
}
#Override
public void addView(View child, int index, ViewGroup.LayoutParams params) {
super.addView(child, index, params);
updateView(child);
}
private void updateView(View view) {
if(view instanceof EditText){
((EditText) view).setTextSize(TypedValue.COMPLEX_UNIT_SP,16);
view.setTag(FontUtil.TAG_CONDENSED_LIGHT);
FontUtil.getInstence(getContext()).setFontByTag(view);
}
}
}
What makes it more complicated is that the minutes have only values (0, 15, 30, 45) and I have to setWrapSelectorWheel to false?
I am thinking if it will be possible to always show the up and down arrows and then disabling scroll.
Change it to an Edittext with the type of number, and use a Toast if the client put a number upper or below of your range. It's more elegant visually, and that will not give you any problem at all
you can use Fantastic PickView library
See PickView
This is a helper lib for us to pick date or province like IOS system WheelView widget.
Maybe you could solve it using a TimePicker.
This could be the layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="wrap_content"
android:padding="8dp"
android:layout_height="wrap_content">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
>
<TimePicker
android:id="#+id/time_picker"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<Button
android:id="#+id/date_time_set"
android:layout_width="match_parent"
android:text="Set"
android:layout_height="wrap_content" />
</LinearLayout>
</ScrollView>
While the dialog could be included in a normal alert:
private void showTimePicker(){
final View dialogView = View.inflate(getActivity(), <time_picker_container_layout_id>, null);
final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
dialogView.findViewById(R.id.date_time_set).setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
TimePicker timePicker = (TimePicker) dialogView.findViewById(R.id.time_picker);
String time = timePicker.getCurrentHour()+":"+timePicker.getCurrentMinute());
dateTime.setText(time);
alertDialog.dismiss();
}});
TimePicker timePicker = (TimePicker) dialogView.findViewById(R.id.time_picker);
timePicker.setCurrentHour(<default_hour>);
timePicker.setCurrentMinute(<default_minute>);
alertDialog.setView(dialogView);
alertDialog.show();
}
If you need to show just the 15', you can round the picked minutes to the closest valid value.
The scrollView in the layout will reduce problems related the picker size.
I hope it helped.
Related
Hello my goal is to make my custom view (ViewCircleOfInterest.java) receiving onClick. Now every time I click onClickListener on ViewCircleOfInterest.java is not called.
My interesting part of layout looks like that:
my_layout.xml
<FrameLayout
android:id="#+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/rl"
android:layout_alignParentTop="true"
android:background="#bbb">
<abc.x.y.ViewCircleOfInterest
android:id="#+id/view_circle_of_interest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</FrameLayout>
I have FrameLayout on my layout and I added view (SurfaceView - CameraPreview.java) to it like that
MyActivity.java
rootView = findViewById(android.R.id.content).getRootView();
viewCircleOfInterest = rootView.findViewById(R.id.view_circle_of_interest);
viewCircleOfInterest.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(NewWayMeasurementActivity.this, "circle a", Toast.LENGTH_SHORT).show();
}
});
(...)
((FrameLayout) rootView.findViewById(R.id.camera_view)).addView(cameraPreview);
(...)
#Override
public boolean dispatchTouchEvent(MotionEvent event) {
return super.dispatchTouchEvent(event);
}
On CameraPreview.java in my init() method I do like that:
(...)
viewCircleOfInterest = ((NewWayMeasurementActivity)activity).viewCircleOfInterest;
viewCircleOfInterest.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(), "circle aa", Toast.LENGTH_SHORT).show();
}
});
I also set onClickListener on my ViewCircleOfInterest.java
public ViewCircleOfInterest(SurfaceView surfaceView) {
super(surfaceView.getContext());
this.surfaceView = surfaceView;
setOnClickListener(this);
}
#Override
public void onClick(View v) {
Toast.makeText(surfaceView.getContext(), "circle aaa", Toast.LENGTH_SHORT).show();
}
But unfortunately non of this method works, I still cannot receive onclicks from my custom view. How to solve that? I hope my question and code is understandable.
Make these changes in your code and check if it works.
my_layout.xml
<FrameLayout
android:id="#+id/camera_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="#+id/rl"
android:layout_alignParentTop="true"
android:background="#bbb">
<abc.x.y.ViewCircleOfInterest
android:id="#+id/view_circle_of_interest"
android:layout_width="wrap_content"
android:clickable="true"
android:layout_height="wrap_content"/>
</FrameLayout>
MyActivity.java
((FrameLayout)rootView.findViewById(R.id.camera_view)).addView(cameraPreview,0);
Here we are adding cameraPreview at 0 index so your custom view is on top now and that should receive clicks.
after adding 2 new features (swipelayout + animation) my ui freezes.
I have a recyclerview which includes movie objects. If i add/remove/modify a movie i call my moviemanager because there's a notify concept (all views which want to use the data have to be registered on this manager).
This all works fine before i added the new features.
I use this swipelayout:
https://github.com/daimajia/AndroidSwipeLayout
Currently the items looks like this:
After swiping:
The freeze is always reproducible if i have 4 items. I swipe on the second item and delete it. Then it will dissapear like i want. After im swiping the "new" second item there's a freeze for like 10-15 seconds.
The layout xml of the item:
<com.daimajia.swipe.SwipeLayout
android:id="#+id/item_movie_swipe_layout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:id="#+id/item_movie_swipe_bottom_wrapper"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ff0000">
<TextView
android:id="#+id/item_movie_bottom_delete_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableTop="#drawable/ic_delete_white_24dp"
android:text="#string/delete"
android:textColor="#fff"
android:layout_gravity="center"
android:padding="10dp"/>
</LinearLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp">
<ImageView
android:id="#+id/item_movie_list_poster"
style="#style/image_border_style"
android:layout_width="68dp"
android:layout_height="100dp"
android:layout_marginRight="3dp"
android:background="#android:color/black"/>
<TextView
android:id="#+id/item_movie_list_name_year"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginBottom="3dp"
android:layout_toEndOf="#+id/item_movie_list_poster"
android:layout_toRightOf="#+id/item_movie_list_poster"
android:gravity="center|left"
android:padding="3dp" android:text="name"/>
<TextView
android:id="#+id/item_movie_list_genre"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/item_movie_list_name_year"
android:layout_marginBottom="3dp"
android:layout_toEndOf="#+id/item_movie_list_poster"
android:layout_toRightOf="#+id/item_movie_list_poster"
android:padding="3dp"
android:text="Drama - Komödie - Action" android:textColor="#color/item_textyear"
android:textSize="12dp"/>
<TextView
android:id="#+id/item_movie_list_viewed"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/item_movie_list_poster"
android:layout_toRightOf="#+id/item_movie_list_poster"
android:paddingLeft="3dp" android:text="Gesehen: "
android:textColor="#color/accept"
android:textSize="12dp"/>
</RelativeLayout>
</com.daimajia.swipe.SwipeLayout>
Relevant code of the adapter:
#Override
public void onBindViewHolder(final CDMMoviesAdapter.IC_ViewHolder p_Holder, final int p_iPosition) {
// more unimportant code...
p_Holder.m_SwipeLayout.setShowMode(SwipeLayout.ShowMode.PullOut);
// Drag From Right
p_Holder.m_SwipeLayout.addDrag(SwipeLayout.DragEdge.Right, p_Holder.m_SwipeLayout.findViewById(R.id.item_movie_swipe_bottom_wrapper));
// Handling different events when swiping
p_Holder.m_SwipeLayout.addSwipeListener(new SwipeLayout.SwipeListener() {
#Override
public void onClose(SwipeLayout layout) {
//when the SurfaceView totally cover the BottomView.
}
#Override
public void onUpdate(SwipeLayout layout, int leftOffset, int topOffset) {
//you are swiping.
}
#Override
public void onStartOpen(SwipeLayout layout) {
}
#Override
public void onOpen(SwipeLayout layout) {
//when the BottomView totally show.
}
#Override
public void onStartClose(SwipeLayout layout) {
}
#Override
public void onHandRelease(SwipeLayout layout, float xvel, float yvel) {
//when user's hand released.
}
});
p_Holder.m_SwipeLayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View p_View) {
if((((SwipeLayout) p_View).getOpenStatus() == SwipeLayout.Status.Close)) {
Intent l_Intent = new Intent();
Bundle l_Bundle = new Bundle();
l_Bundle.putLong(CDMMovieDetailsActivity.ARG_MOVIE, l_MovieID);
l_Intent.putExtras(l_Bundle);
l_Intent.setClass(l_Context, CDMMovieDetailsActivity.class);
l_Context.startActivity(l_Intent);
}
}
});
p_Holder.m_tvDelete.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View p_View) {
Animation l_DeleteAnimation = AnimationUtils.loadAnimation(l_Context, R.anim.slide_out);
l_DeleteAnimation.setAnimationListener(new Animation.AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
mItemManger.removeShownLayouts(p_Holder.m_SwipeLayout);
CDMMovieManager.getInstance().removeMovieID(m_List, m_MovieIDs.get(p_iPosition));
mItemManger.closeAllItems();
}
});
p_Holder.m_View.startAnimation(l_DeleteAnimation);
}
});
// mItemManger is member in RecyclerSwipeAdapter Class
mItemManger.bindView(p_Holder.itemView, p_iPosition);
// more unimportant code...
}
/**
* This class is the viewholder. For internal use only.
*/
public static class IC_ViewHolder extends RecyclerView.ViewHolder {
/**
* Constructor
*
* #param p_View the view
*/
public IC_ViewHolder(View p_View) {
super(p_View);
m_View = p_View;
m_SwipeLayout = (SwipeLayout) p_View.findViewById(R.id.item_movie_swipe_layout);
m_tvNameYear = (TextView) p_View.findViewById(R.id.item_movie_list_name_year);
m_ivPoster = (ImageView) p_View.findViewById(R.id.item_movie_list_poster);
m_tvGenre = (TextView) p_View.findViewById(R.id.item_movie_list_genre);
m_tvViewed = (TextView) p_View.findViewById(R.id.item_movie_list_viewed);
m_tvDelete = (TextView) p_View.findViewById(R.id.item_movie_bottom_delete_desc);
}
public View m_View;
public SwipeLayout m_SwipeLayout;
public TextView m_tvNameYear;
public ImageView m_ivPoster;
public TextView m_tvGenre;
public TextView m_tvViewed;
public TextView m_tvDelete;
}
In CDMMovieManager.getInstance().removeMovieID(m_List, m_MovieIDs.get(p_iPosition)); the movie will be removed and all registered views will be notified. In this case the fragment of this adapter will call m_Adapter.notifyDataSetChanged();
The animation file:
<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android">
<translate
android:duration="250"
android:fromXDelta="0%"
android:toXDelta="-100%"/>
</set>
I tried things like View.clearAnimation() or Animation.setAnimationListener(null) but i always get this problem.
Plase ask if you need more informations.
Update:
Problem only occures if i try to swipe the next item. (For example delete 2nd item. After that try to swipe the 3rd item which is the new second item -> freeze on the item i tried to swipe). The freeze can only be removed on swiping on any other item.
I solved my problem. This answer helped me: How to animate RecyclerView items when they appear
I added this code to my adapter:
#Override
public void onViewDetachedFromWindow(IC_ViewHolder p_Holder) {
p_Holder.m_View.clearAnimation();
}
I have a main activity (ActivityMain.java) that I would like to use to navigate between four fragments. In one of these fragments, I'm attempting to place a CardView in conjunction with a RecyclerView to create a vertical list of cards. However, so far I've been unable to get any of the cards to display when I run the app. The CardView will display perfectly in Android Studio's design preview, but when an actual device/emulator is used it disappears.
I've tried to manually set the visibility of the CardView through Java, but it continued to stay invisible. I believe that the fragment's layout could be covering the CardView's layout, but I'm still very new to Android development so I'm not completely sure what the problem could be.
Below I've pasted the classes and XML files that are likely to be associated with my problem.
AdapterMainFeed.java
public class AdapterMainFeed extends RecyclerView.Adapter<AdapterMainFeed.ViewHolderMainFeed> {
private ArrayList<Article> listArticlesMain = new ArrayList<>();
private LayoutInflater inflater;
public AdapterMainFeed(Context context) {
inflater = LayoutInflater.from(context);
}
public void setArticlesMain(ArrayList<Article> listArticlesMain) {
this.listArticlesMain = listArticlesMain;
notifyDataSetChanged();
}
#Override
public ViewHolderMainFeed onCreateViewHolder(ViewGroup container, int i) {
View layout = inflater.inflate(R.layout.view_main_feed, container, false);
Article article1 = new Article("asdf", "ghj", "klm", new Date(0));
Article article2 = new Article("sdfg", "hjk", "lmn", new Date(0));
Article article3 = new Article("dfgh", "jkl", "mno", new Date(0));
listArticlesMain.add(article1);
listArticlesMain.add(article2);
listArticlesMain.add(article3);
return new ViewHolderMainFeed(layout);
}
#Override
public void onBindViewHolder(ViewHolderMainFeed viewHolderMainFeed, int i) {
Article currentArticle = listArticlesMain.get(i);
viewHolderMainFeed.articleTitle.setText(currentArticle.getTitle());
viewHolderMainFeed.articleAuthor.setText(currentArticle.getAuthor());
viewHolderMainFeed.articleWebsite.setText(currentArticle.getWebsite());
DateFormat formatter = DateFormat.getDateTimeInstance();
final String timePosted = formatter.format(currentArticle.getTimePosted());
viewHolderMainFeed.articleTime.setText(timePosted);
}
#Override
public void onAttachedToRecyclerView(RecyclerView recyclerView) {
super.onAttachedToRecyclerView(recyclerView);
}
#Override
public int getItemCount() {
return listArticlesMain.size();
}
static class ViewHolderMainFeed extends RecyclerView.ViewHolder {
TextView articleTitle;
TextView articleAuthor;
TextView articleWebsite;
TextView articleTime;
public ViewHolderMainFeed(View itemView) {
super(itemView);
articleTitle = (TextView) itemView.findViewById(R.id.mainArticleTitle);
articleAuthor = (TextView) itemView.findViewById(R.id.mainArticleAuthor);
articleWebsite = (TextView) itemView.findViewById(R.id.mainArticleWebsite);
articleTime = (TextView) itemView.findViewById(R.id.mainArticleTime);
}
}
}
view_main_feed.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"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
tools:context="com.convergeapp.converge.ActivityMain">
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
card_view:cardCornerRadius="7dp"
card_view:cardBackgroundColor="#color/colorPurpleSeance"
android:id="#+id/mainArticleCard"
android:layout_width="match_parent"
android:layout_height="300dp"
android:padding="8dp"
android:clickable="true">
<RelativeLayout
android:id="#+id/mainArticleLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">
<TextView
android:id="#+id/mainArticleTitle"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"/>
<TextView
android:id="#+id/mainArticleAuthor"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_below="#id/mainArticleTitle"/>
<TextView
android:id="#+id/mainArticleWebsite"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_below="#+id/mainArticleTime"/>
<TextView
android:id="#+id/mainArticleTime"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
After playing around with some changes, I finally discovered the solution. What I did was add the Article objects to the list in the main fragment's onCreateView method. Additionally, I instantiated CardView in the ViewHolder, though that didn't help me see the cards initially.
So, if you're ever in a similar predicament and can't figure out the solution, try to actually create the objects before setting them.
You need to call notifyDataSetChanged(); inside onCreateViewHolder after adding the new articles so that the itemcount is updated
this is my last desperate attempt to fix this problem.
i am using dialogfragment to make my dialog window MyDialog. the window is supposed to show a score I have sent with and the user can then write in their name and confirm. i am then supposed to be able to retrieve their name.
My first problem is that the edittext that are supposed to show the score, doesn't want to show the score i set the edittext to be (it will only show new text if it was in the xml file). I can however still retrieve the correct score(text) afterwards from the same edittext.
The second problem is that the text that the user writes in can't be retrieved since the edittext isn't updating. However the text that was in the field from the xml file can be retrieved.
It seems like the edittext doesn't want to refresh after they are made in the xml file.
the dialog class (imports taken out):
public class MyDialog extends DialogFragment
{
private EditText scoreEdit;
private EditText userEdit;
private DialogClickListener callback;
public interface DialogClickListener
{
public void onFinishedClick();
}
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
try
{
callback = (DialogClickListener) getActivity();
}catch(ClassCastException e)
{
throw new ClassCastException("called class must implement interface");
}
}
public static MyDialog newInstance(int title)
{
MyDialog frag = new MyDialog();
Bundle args = new Bundle();
args.putInt("tittel",title);
frag.setArguments(args);
return frag;
}
#Override
public Dialog onCreateDialog(Bundle savedInstanceState)
{
AlertDialog.Builder dialog = new AlertDialog.Builder(getActivity());
LayoutInflater inflater = getActivity().getLayoutInflater();
View inflatedView = inflater.inflate(R.layout.dig_lay, null);
scoreEdit = (EditText) inflatedView.findViewById(R.id.dialogScoreEdit);
userEdit = (EditText) inflatedView.findViewById(R.id.dialogUsernameEdit);
scoreEdit.setText("score supposed to change");
// scoreEdit (edittext) is not changing
dialog.setView(inflater.inflate(R.layout.dig_lay, null));
dialog.setTitle("Title");
dialog.setPositiveButton("reg1", new DialogInterface.OnClickListener()
{
#Override
public void onClick(DialogInterface dialog, int whichButton)
{
System.out.println("new text supposed to be: " + userEdit.getText().toString());
//old text from xml shows
callback.onFinishedClick();
}
});
setCancelable(false);
return dialog.create();
}
}
the XML file for the dialog window:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/dialogLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="16dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="4dp">
<TextView
android:text="score"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<EditText
android:id="#+id/dialogScoreEdit"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:hint="score here"
android:inputType="none"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="4dp"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:layout_marginBottom="16dp"
android:fontFamily="sans-serif">
<TextView
android:text="Username"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<EditText
android:id="#+id/dialogUsernameEdit"
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="retrive this"
android:inputType="none"/>
</LinearLayout>
</LinearLayout>
picture of the dialogwindow: http://i.stack.imgur.com/EvwSe.png
I have tried calling onResume() and putting the new score in. but the edittext still doesn't change.
I appreciate any answer and sorry for any bad English :)
It looks like there are a few issues there. The ones I have noticed are that when you set your view you are reinflating the view, versus setting it to the view you have already set up when you do
dialog.setView(inflater.inflate(R.layout.dig_lay, null));
you want to set that instead to
dialog.setView(inflatedView);
Also, since we can't see the actual data you are putting into the EditText, we can't see if that might be null, etc.
Finally, I never see you run a scoreEdit.getText(), so you wouldn't be retrieving any changes the user made to the edittext.
I'm making a very simple Andriod app and I was wondering if I could get some help with my app.
I would like to show an ImageView over the full ListView (including the action bar) for 3 seconds, and then remove the ImageView (or hide it, anything), to go back to the list view.
How can this be done? I have tried a few things but it either breaks my code or doesn't show anything at all.
Thanks in advance everyone - let me know if you need any further explanation.
EDIT: As per the question below, I'd like the ImageView to be shown as soon as the ListView is shown, for 3 seconds, then disappear.
Allright. What you want is actually quite easy.
Simply create a RelativeLayout that contains a ListView and an ImageView above it.
Then inside your onCreate(...) method, you use a Handler and set the Visibility of the ImageView to GONE after 3 seconds.
Here is the layout.xml file:
<?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" >
<ListView
android:id="#+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" >
</ListView>
<ImageView
android:id="#+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
android:src="#drawable/your_image" />
</RelativeLayout>
And inside the onCreate(...) method:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.yourlayout);
final ImageView iv = (ImageView) findViewById(R.id.imageView1);
Handler h = new Handler();
h.postDelayed(new Runnable() {
#Override
public void run() {
// EITHER HIDE IT IMMEDIATELY
iv.setVisibility(View.GONE);
// OR HIDE IT USING ANIMATION
hideImageAnimated(iv);
// DONT use both lines at the same time :)
}
}, 3000); // 3 seconds
}
In order to make things a bit smoother, you could use an AlphaAnimation on your ImageView:
public void hideImageAnimated(final ImageView iv) {
Animation alpha = new AlphaAnimation(1.0f, 0.0f);
alpha.setDuration(1000); // whatever duration you want
// add AnimationListener
alpha.setAnimationListener(new AnimationListener(){
#Override
public void onAnimationEnd(Animation arg0) {
iv.setVisibility(View.GONE);
}
#Override
public void onAnimationRepeat(Animation arg0) { }
#Override
public void onAnimationStart(Animation arg0) { }
});
iv.startAnimation(alpha);
}