Im using android studio , i have xml which have horizontalscrollview
Then linearlayout then multiple imageviews ..
<HorizontalScrollView
android:id="#+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher" />
</LinearLayout>
What i need is to make this horizantalscrollview to keep automatically infinite scrolling the images till the end then repeat the scrolling again and again.
what i mean by auto scrolling that the horizontalscrollview keep scrolling without using hand
Did you try to use wrap_content in layout_width?
Now, u adapt your width layout to the width of the screen, i think that if u put the value wrap_content it will solve ur problem (u have layout_height=wrap_content, but the height is "asociated" with a Vertical scroll, not with horizontal scroll):
android:layout_width="wrap_content"
I hope this help u.
ok Thanks for your support .. i found the solution
Timer timer1 = new Timer("horizontalScrollViewTimer");
timer1.scheduleAtFixedRate(new TimerTask() {
#Override
public void run() {
runOnUiThread(new Runnable() {
#Override
public void run() {
if (scrollingLeft) {
if (scroll.getScrollX() == 0) {
scroll.smoothScrollBy(5, 0);
scrollingLeft = false;
} else {
scroll.smoothScrollBy(-5, 0);
}
} else {
if (scroll.canScrollHorizontally(View.FOCUS_RIGHT)) {
scroll.smoothScrollBy(5, 0);
} else {
scroll.smoothScrollBy(-5, 0);
scrollingLeft = true;
}
}
}
});
}
}, 1000, 50);
Related
I am going to implement a progress bar with two clip textview on it.
Something like:
I use some trick (using paddingEnd/paddingStart, back/front textview to achieve the clip effect for textview) to implement it:
// part of activity
TextView leftFrontText;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
View view = View.inflate(this, R.layout.test_page_layout, containerLayout);
View progressBar = view.findViewById(R.id.progress_bar);
leftFrontText = view.findViewById(R.id.left_front_textview);
int progress = 59;
ValueAnimator va = ValueAnimator.ofFloat(0f, progress);
int mDuration = 1000;
va.setDuration(mDuration);
va.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
public void onAnimationUpdate(ValueAnimator animation) {
float value = (float)animation.getAnimatedValue();
setViewWidth(progressBar, (int)value);
setLeftFrontTextViewPadding((int)value);
}
});
// va.addListener(new Animator.AnimatorListener() {
// #Override
// public void onAnimationStart(Animator animation) {
//
// }
//
// #Override
// public void onAnimationEnd(Animator animation) {
// setLeftFrontTextViewPadding(progress);
// }
//
// #Override
// public void onAnimationCancel(Animator animation) {
//
// }
//
// #Override
// public void onAnimationRepeat(Animator animation) {
//
// }
// });
va.start();
}
private void setViewWidth(View view, int dp) {
ViewGroup.LayoutParams layoutParams = view.getLayoutParams();
layoutParams.width = ThemeUtil.dpToPx(this, dp);
view.setLayoutParams(layoutParams);
}
private void setLeftFrontTextViewPadding(int progressBarDp) {
int marginStart = ThemeUtil.dpToPx(TestPageActivity.this, 12);
leftFrontText.post(new Runnable() {
#Override
public void run() {
int textViewLength = leftFrontText.getWidth();
int progressbarDistance = ThemeUtil.dpToPx(TestPageActivity.this, progressBarDp);
if (textViewLength >= 0) {
int padding = marginStart + textViewLength - progressbarDistance;
leftFrontText.setPadding(0, 0, padding > 0 ? -padding : 0, 0);
}
}
});
}
And the layout is:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="28dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#drawable/rounded_corner_bg_for_cashlfow_homepage_category_cell"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
>
<TextView
android:id="#+id/left_bottom_textview"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:gravity="center_vertical"
android:text="Entertatinment"
android:textSize="#dimen/main_text_size"
android:maxLines="1"
android:ellipsize="end"
android:textColor="#color/grey1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="12dp"
/>
<View
android:id="#+id/progress_bar"
android:layout_width="10dp"
android:layout_height="match_parent"
android:background="#drawable/rounded_corner_front_progreebar_homepage_category_cell"
app:layout_constraintStart_toStartOf="parent"
/>
<TextView
android:id="#+id/left_front_textview"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:gravity="center_vertical|start"
android:text="Entertatinment"
android:textSize="#dimen/main_text_size"
android:maxLines="1"
android:ellipsize="end"
android:textColor="#color/white"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
android:layout_marginStart="12dp"
/>
<TextView
android:id="#+id/right_bottom_amount_textview"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:gravity="center_vertical|end"
android:text="$0 / $0"
android:textSize="#dimen/main_text_size"
android:maxLines="1"
android:textColor="#color/white"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="12dp"
/>
<TextView
android:id="#+id/right_front_amount_textview"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:gravity="center_vertical|end"
android:text="$0 / $0"
android:textSize="#dimen/main_text_size"
android:maxLines="1"
android:textColor="#color/black1"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:layout_marginEnd="12dp"
android:paddingStart="0dp"
/>
</android.support.constraint.ConstraintLayout>
When I run this code, it almost achieved the effect I want. But it has one issue. Textview keeps flashing while doing animation, and when animation finished, the color of textview sometime turn all white.
I think there may be something wrong in leftFrontText.post() of setLeftFrontTextViewPadding, like how I get width of textview. But I can't be quite sure. Can anyone show me the right way to do this? Or any other better way to implement this kind of progress bar.
Why not try this approach and leverage the power of ConstraintLayout as your progressBar:
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/parentview"
android:layout_width="360dp"
android:layout_height="28dp"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:background="#ddddff"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp">
<TextView
android:id="#+id/left_bottom_textview"
android:layout_width="180dp"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:text="Entertainment"
android:maxLines="1"
android:ellipsize="end"
android:textColor="#404040"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:id="#+id/right_front_amount_textview"
android:layout_width="180dp"
android:layout_height="0dp"
android:gravity="center_vertical|end"
android:text="$0 / $0"
android:maxLines="1"
android:textColor="#color/black"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent" />
<android.support.constraint.ConstraintLayout
android:id="#+id/progress_bar"
android:layout_width="50dp"
android:layout_height="match_parent"
app:layout_constraintStart_toStartOf="parent"
android:background="#004090">
<TextView
android:id="#+id/left_front_textview"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:text="Entertainment"
android:singleLine="true"
android:textColor="#fff"
android:ellipsize="none"
android:layout_paddingStart="12dp"
android:layout_paddingLeft="12dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"/>
<TextView
android:id="#+id/right_bottom_amount_textview"
android:layout_width="180dp"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical|end"
android:text="$0 / $0"
android:layout_alignRight="#id/left_front_textview"
android:textColor="#ffffff"
android:layout_paddingEnd="12dp"
android:layout_paddingRight="12dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toEndOf="#id/left_front_textview"/>
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
So basically we would have:
The Parent layout (parentview): having a fixed layout_width 360dp and contains the initial Grey TextViews
The Progress layout (progress_bar): also having a fixed size 360dp and contains the front White TextViews
Hence we overlay the Progress layout (progress_bar) ontop of its parent layout and increase or decrease the layout_width to simulate a progress without flickering:
The image below shows the progress layout having a static layout_width of 74dp; Also note that progress layout_width based on the example provided above can range from 1dp to max:360dp or otherwise 1% to 100% of parentview width.
The Problem
I have a recycler view with card items. These card items contain only text and are expandable.It looks like this Collapsed Expanded
Now I expand and collapse one of them sometimes and scroll around and somehow there appears now more whitespace between the cards:
Whitespace between cards
Moreover, for cards with long text when I click to collapse them, this appears:
Big Cards
The Code
xml:
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<com.ramotion.foldingcell.FoldingCell
android:id="#+id/folding_cell"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
app:backSideColor="#F5F5F5">
<FrameLayout
android:id="#+id/cell_content_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="300dp"
android:visibility="gone">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/movie_card2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:foreground="?attr/selectableItemBackground"
android:minHeight="300dp"
cardview:cardBackgroundColor="#color/card_background"
cardview:cardCornerRadius="1dp"
cardview:cardElevation="4dp"
cardview:cardUseCompatPadding="true">
<RelativeLayout
android:id="#+id/review_item2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical">
<View
android:id="#+id/review_detail_header"
android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/material_red_400" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#id/review_detail_header"
android:layout_alignTop="#id/review_detail_header"
android:layout_centerHorizontal="true"
android:gravity="center"
android:text="Review Details"
android:textColor="#color/text_secondary" />
<ImageView
android:id="#+id/ic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/review_detail_header"
android:layout_marginTop="#dimen/material_layout_keylines_horizontal_margin"
android:adjustViewBounds="true"
android:paddingLeft="#dimen/material_layout_keylines_horizontal_margin"
android:paddingRight="#dimen/material_layout_keylines_horizontal_margin"
android:src="#drawable/ic_account_circle_white_24dp"
android:tint="#color/accent"
tools:ignore="ContentDescription" />
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="#+id/review_author2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#id/review_detail_header"
android:layout_gravity="center_vertical"
android:layout_marginTop="#dimen/material_layout_keylines_horizontal_margin"
android:layout_toRightOf="#id/ic"
android:textSize="14sp"
custom:robotoType="bold"
tools:text="User Name" />
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="#+id/review_body2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/review_author2"
android:layout_marginBottom="#dimen/material_layout_keylines_horizontal_margin"
android:layout_marginLeft="56dp"
android:layout_marginRight="24dp"
android:layout_marginTop="#dimen/material_layout_vertical_spacing_between_content_areas"
android:layout_weight="1"
android:ellipsize="none"
android:maxLines="100"
android:scrollHorizontally="false"
android:textSize="14sp"
custom:robotoType="regular"
tools:text="The movie's review goes here..." />
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="#+id/review_spoiler2"
style="#style/ReviewBodyStyle"
android:text="#string/reviews_alert"
android:textColor="#color/primary"
android:visibility="gone"
custom:robotoType="bold" />
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="#+id/review_time2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/review_body2"
android:layout_margin="#dimen/material_layout_keylines_horizontal_margin"
android:textSize="#dimen/material_layout_keylines_horizontal_margin"
android:visibility="gone"
custom:robotoType="regular"
tools:text="01 Jan 2016" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
<FrameLayout
android:id="#+id/cell_title_view"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/movie_card"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:foreground="?attr/selectableItemBackground"
cardview:cardBackgroundColor="#color/card_background"
cardview:cardCornerRadius="1dp"
cardview:cardElevation="4dp"
cardview:cardUseCompatPadding="true">
<RelativeLayout
android:id="#+id/review_item"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:orientation="vertical"
android:padding="#dimen/material_layout_keylines_horizontal_margin">
<ImageView
android:id="#+id/ic2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:adjustViewBounds="true"
android:src="#drawable/ic_account_circle_white_24dp"
android:tint="#color/accent"
tools:ignore="ContentDescription" />
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="#+id/review_author"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/material_layout_keylines_horizontal_margin"
android:layout_toRightOf="#+id/ic2"
custom:robotoType="bold"
android:textSize="14sp"
tools:text="User Name" />
<!-- Review open icon -->
<ImageView
android:id="#+id/review_open"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:adjustViewBounds="true"
android:src="#drawable/ic_open_in_new_white_24dp"
android:tint="#color/accent"
tools:ignore="contentDescription" />
<!-- Review Body -->
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="#+id/review_body"
style="#style/ReviewBodyStyle"
android:layout_marginLeft="40dp"
android:layout_marginRight="8dp"
android:layout_below="#+id/review_spoiler"
custom:robotoType="regular"
tools:text="The movie's review goes here..." />
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="#+id/review_spoiler"
style="#style/ReviewBodyStyle"
android:layout_below="#id/review_open"
android:text="#string/reviews_alert"
android:textColor="#color/primary"
android:layout_marginLeft="40dp"
android:layout_marginRight="8dp"
android:visibility="gone"
custom:robotoType="bold" />
<com.mt.moviesiwanttowatch.ui.widget.TextViewRoboto
android:id="#+id/review_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/review_body"
android:layout_margin="#dimen/material_layout_keylines_horizontal_margin"
android:textSize="#dimen/material_layout_keylines_horizontal_margin"
android:visibility="gone"
custom:robotoType="regular"
tools:text="01 Jan 2016" />
</RelativeLayout>
</android.support.v7.widget.CardView>
</FrameLayout>
</com.ramotion.foldingcell.FoldingCell>
</layout>
The adapter:
public class ReviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
public ArrayList<Review> reviewList;
public int foldingCellPosition = -1;
public FoldingCell currentFoldingCell;
// Constructor
public ReviewAdapter(ArrayList<Review> reviewList) {
this.reviewList = reviewList;
}
// RecyclerView methods
#Override
public int getItemCount() {
return reviewList.size();
}
#Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
ViewGroup v = (ViewGroup) LayoutInflater.from(parent.getContext()).inflate(R.layout.item_list_review, parent, false);
return new ReviewViewHolder(v);
}
#Override
public void onBindViewHolder(RecyclerView.ViewHolder viewHolder, int position) {
Review review = reviewList.get(position);
ReviewViewHolder holder = (ReviewViewHolder) viewHolder;
if (position == foldingCellPosition) {
holder.binding.foldingCell.unfold(true);
holder.binding.reviewBody2.setText(review.getComment());
holder.binding.reviewAuthor2.setText(review.getUsername());
return;
}
holder.binding.foldingCell.fold(true);
holder.binding.reviewAuthor.setText(review.getUsername());
if (review.isHasSpoiler()) {
holder.binding.reviewBody.setVisibility(View.GONE);
holder.binding.reviewSpoiler.setVisibility(View.VISIBLE);
} else {
holder.binding.reviewBody.setText(review.getComment());
holder.binding.reviewBody.setVisibility(View.VISIBLE);
holder.binding.reviewSpoiler.setVisibility(View.GONE);
}
holder.binding.reviewTime.setText(review.getCreatedAt());
}
// ViewHolder
public class ReviewViewHolder extends RecyclerView.ViewHolder {
ItemListReviewBinding binding;
public ReviewViewHolder(final ViewGroup itemView) {
super(itemView);
binding = DataBindingUtil.bind(itemView);
binding.reviewItem.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// onReviewClickListener.onReviewClicked(getAdapterPosition());
Log.e("TEST", "CLIKC");
if (foldingCellPosition != -1) {
currentFoldingCell.fold(false);
}
currentFoldingCell = binding.foldingCell;
binding.reviewBody2.setText(reviewList.get(getAdapterPosition()).getComment());
binding.reviewAuthor2.setText(reviewList.get(getAdapterPosition()).getUsername());
binding.foldingCell.toggle(false);
foldingCellPosition = getAdapterPosition();
}
});
binding.reviewItem2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
binding.reviewItem2.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
foldingCellPosition = -1;
binding.foldingCell.fold(false);
}
});
}
});
}
}
}
How the recycler view is created:
layoutManager = new LinearLayoutManager(getContext());
mBinding.movieDetailReviewListRvReviews.setHasFixedSize(true);
mBinding.movieDetailReviewListRvReviews.setLayoutManager(layoutManager);
mBinding.movieDetailReviewListRvReviews.setAdapter(adapter);
What I tried so far
I really dont have any idea why this happens.
However I tried notifyDataSetChanged() after each collapse/expand as well as invalidate().
Edit
For the collapsing / expanding effect I use this library:https://github.com/Juriv/folding-cell-android
Actually there were a lot of problems with my code. First of all, as rom4ek mentioned, I had to change foldingCellPosition = getAdapterPosition() to foldingCellPosition = getLayoutPosition(). The next Problem, was this call:
if(foldingCellPosition != -1) {
currentFoldingCell.fold(false);
}
Not visible views should fold, which resulted in strange behaviour, so I added this code:
public void checkForHide(int first, int last){
if(foldingCellPosition != -1){
if(foldingCellPosition < first || foldingCellPosition > last){
foldingCellPosition = -1;
}
}
}
If the unfolded view is not visible the folding cellposition will set to -1 instead of folding it manually.
It is called from the Fragment here:
mBinding.movieDetailReviewListRvReviews.addOnScrollListener(new RecyclerView.OnScrollListener() {
#Override
public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
super.onScrolled(recyclerView, dx, dy);
// Load more data if reached the end of the list
adapter.checkForHide(layoutManager.findFirstVisibleItemPosition(), layoutManager.findLastVisibleItemPosition());
if (layoutManager.findLastVisibleItemPosition() == adapter.reviewList.size() - 1 && !isLoadingLocked && !isLoading) {
if (pageToDownload < totalPages) {
mBinding.layoutContent.pbLoadingMore.setVisibility(View.VISIBLE);
downloadMovieReviews();
}
}
}
});
Try leaving cardview:cardUseCompatPadding false, which is the default.
From https://developer.android.com/reference/android/support/v7/widget/CardView.html#setUseCompatPadding(boolean)
setUseCompatPadding
added in version 24.2.0 void setUseCompatPadding (boolean
useCompatPadding) CardView adds additional padding to draw shadows on
platforms before Lollipop.
This may cause Cards to have different sizes between Lollipop and
before Lollipop. If you need to align CardView with other Views, you
may need api version specific dimension resources to account for the
changes. As an alternative, you can set this flag to true and CardView
will add the same padding values on platforms Lollipop and after.
Since setting this flag to true adds unnecessary gaps in the UI,
default value is false.
This implies that the CardView may be adding padding when you collapse/expand cards.
I have a layout that I am trying to make visible and it is currently not working. The layout I want to make visible has the id "goal_reminder" below. The visibility is set to "GONE" in the xml.
Here is the xml
<?xml version="1.0" encoding="utf-8"?>
<com.View.pages.ActivityPage
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<android.support.v4.widget.SwipeRefreshLayout
android:id="#+id/activity_refresh"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
android:id="#+id/activitylist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#e7e6ee"
android:clipToPadding="false"
android:divider="#null"
android:paddingBottom="80dp" />
</android.support.v4.widget.SwipeRefreshLayout>
<RelativeLayout
android:id="#+id/goal_reminder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/transparent_color"
android:orientation="vertical"
android:visibility="gone">
<ImageView
android:layout_width="match_parent"
android:layout_height="145dp"
android:src="#drawable/sunsetforgoal" />
<ImageView
android:layout_width="200dp"
android:layout_height="50dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/goal_reminder_title"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="35dp"
android:src="#drawable/logo" />
<TextView
android:id="#+id/goal_reminder_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginTop="10dp"
android:text="No goal in progress"
android:textColor="#color/text_color"
android:textSize="26sp" />
<TextView
android:id="#+id/goal_reminder_message"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/goal_reminder_title"
android:layout_marginLeft="20dp"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="Create a new goal in your \nprofile."
android:textColor="#color/text_color"
android:textSize="18sp" />
</RelativeLayout>
<TextView
android:id="#+id/playground_welcome"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:autoLink="all"
android:gravity="center_horizontal"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:text="#string/welcome_string"
android:textSize="18sp"
android:visibility="gone" />
</com.View.pages.ActivityPage>
Here is the onFinishInflate(I am using the Screenplay/Flow libraries so that is taking place of onCreate). As you can see I am trying to set goalReminderLayout.setVisibility(View.Visible) and it's not actually making it visible. I have tested this same line of code outside of the if statements and it works just fine. I have also tested to make sure it's reaching that line of code in the if statements and that part is working fine, the lastTriggerDate is being saved properly in Parse. I am lost on why it's working fine outside of the if statements in the onFinishInflate. I also tested with a Log.d("TestVisiblity", goalReminderLayout.getVisibility()); which returns a 0(Visible) so it seems like its visible but its not actually showing up on my screen.
Date lastTriggerDate = new Date();
Boolean noDateInParse = false;
if (currentUser.getLastTriggerDate() != null) {
lastTriggerDate = currentUser.getLastTriggerDate();
} else {
noDateInParse = true;
}
Boolean inToday = DateUtils.isToday(lastTriggerDate.getTime());
if (!inToday) {
currentUser.setLastTriggerDate(currentTime);
currentUser.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
goalReminderLayout.setVisibility(View.VISIBLE);
fireGoalReminderAlert();
} else {
e.printStackTrace();
}
}
});
} else if (noDateInParse) {
currentUser.setLastTriggerDate(currentTime);
currentUser.saveInBackground(new SaveCallback() {
#Override
public void done(ParseException e) {
if (e == null) {
goalReminderLayout.setVisibility(View.VISIBLE);
fireGoalReminderAlert();
} else {
e.printStackTrace();
}
}
});
}
Here is the code for fireGoalReminderAlert(); It's just set to set the visibility back to gone after 10 seconds. I commented this line out when testing and still had no luck so I don't think this is causing the problem.
public void fireGoalReminderAlert() {
Runnable mRunnable;
Handler mHandler = new Handler();
mRunnable = new Runnable() {
#Override
public void run() {
goalReminderLayout.setVisibility(View.GONE);
}
};
mHandler.postDelayed(mRunnable, 10 * 1000);
}
When you set a layout to visible from gone it's always a good idea to invalidate view to allow a redraw on the layout.
goalReminderLayout.setVisibility(View.VISIBLE);
goalReminderLayout.invalidate();
look at the android documentation for more info
http://developer.android.com/reference/android/view/View.html
Try this
Handler(Looper.getMainLooper()).post {
goalReminderLayout.setVisibility(View.VISIBLE);
}
So I have 4 normal imagebuttons that I have set up and then a 5th imagebutton that is a drag and drop. I want the 4 non drag and drop imagebuttons to stay in a particular spot no matter what happens with the imagebutton that is drag and drop. When I move my drag and drop imagebutton, the other imagebuttons get moved and are being squished also.
Any idea how I can move this drag and drop imagebutton without affecting the other imagebuttons in any way?
Here is my xml:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gllayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#drawable/mars" >
<TextView
android:id="#+id/scores"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/mainHut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mainhut" />
<ImageButton
android:id="#+id/polarCapButton1"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/polarcap" />
<ImageButton
android:id="#+id/polarCapButton2"
android:layout_marginTop="-70dp"
android:layout_marginLeft="575dp"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/polarcap" />
<ImageButton
android:id="#+id/spaceRockButton1"
android:layout_marginTop="100dp"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/spacerock" />
<ImageButton
android:id="#+id/spaceRockButton2"
android:layout_marginTop="-140dp"
android:layout_marginLeft="520dp"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/spacerock" />
<ImageButton
android:id="#+id/meteor"
android:visibility="invisible"
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/meteor"
android:layout_marginTop="-100dp"
android:layout_marginLeft="400dp" />
</LinearLayout>
Here is the code for my drag and drop imagebutton:
mainHut = (ImageButton) findViewById(R.id.mainHut);
mainHut.setOnTouchListener(new OnTouchListener()
{
#Override
public boolean onTouch(View v, MotionEvent event)
{
if (event.getAction() == MotionEvent.ACTION_DOWN)
{
mainHutSelected = true;
}//end if
if (event.getAction() == MotionEvent.ACTION_UP)
{
if (mainHutSelected == true)
{
mainHutSelected = false;
}//end if
}//end if
else if (event.getAction() == MotionEvent.ACTION_MOVE)
{
if (mainHutSelected == true)
{
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(v.getWidth(), v.getHeight());
params.setMargins((int)(event.getRawX() - event.getRawY() / 2), (int) (event.getRawY() - v.getHeight() * 1.5), (int) (event.getRawX() - v.getWidth() / 2), (int) (event.getRawY() - v.getHeight() * 1.5));
v.setLayoutParams(params);
}//end if
}//end else
return false;
}//end onTouch function
});//end setOnClickListener
Thanks in advance for the help.
I suggest you use a FrameLayout. This will make your imageviews stackable.
<FrameLayout>
<ImageButton/>
<ImageButton/>
<ImageButton/>
<ImageButton/>
<ImageButton/>
</FrameLayout>
You will need to set them all to have a static position on the screen based on its parents origin. The 5th ImageButton, you can use it to set the onTouch listener like you did.
Edit: OR you can do something like this (If you wanna keep the linear layout):
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gllayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/mars"
android:orientation="vertical" >
<TextView
android:id="#+id/scores"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageButton
android:id="#+id/polarCapButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/polarcap"
android:orientation="vertical" />
<ImageButton
android:id="#+id/polarCapButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="575dp"
android:layout_marginTop="-70dp"
android:background="#drawable/polarcap"
android:orientation="vertical" />
<ImageButton
android:id="#+id/spaceRockButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="100dp"
android:background="#drawable/spacerock"
android:orientation="vertical" />
<ImageButton
android:id="#+id/spaceRockButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="520dp"
android:layout_marginTop="-140dp"
android:background="#drawable/spacerock"
android:orientation="vertical" />
<ImageButton
android:id="#+id/meteor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="400dp"
android:layout_marginTop="-100dp"
android:background="#drawable/meteor"
android:orientation="vertical"
android:visibility="invisible" />
</LinearLayout>
<ImageButton
android:id="#+id/mainHut"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="put offset here"
android:background="#drawable/mainhut" />
</FrameLayout>
Just change the marginTop on mainHut to the offset you want to set it at!
Without looking at your XML file, it is probably due to the use of a relative layout - the 4 static buttons may be positioned relative to the button that is being moved, and will move in real-time when dragging and dropping. Try using absolute positioning (e.g., android:layout_marginTop="30dp") instead of relative, or using another type of layout. If you could post both your Activity where this happens and your XML file for that layout, that will better help provide some information for more appropriate answers.
I'm not sure if this is what you want.
But you could use a floating imageButton, using the Window Manager. But this way the button would be a standalone overlay and no longer be part of the 4-buttons View. See this post: What APIs in Android is Facebook using to create Chat Heads?
I have the following xml:
<LinearLayout
android:id="#+id/searchBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/theTitleBar"
android:orientation="horizontal" >
<EditText
android:id="#+id/searchBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="6dp"
android:layout_marginLeft="7dp"
android:layout_marginRight="1dp"
android:layout_marginTop="8dp"
android:layout_weight="1"
android:background="#drawable/text_area_search"
android:imeOptions="actionSearch"
android:textSize="14dp" >
<requestFocus />
</EditText>
<ImageButton
android:id="#+id/speechRecognition"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right|center_vertical"
android:layout_marginRight="7dp"
android:layout_weight="0"
android:background="#drawable/recording_bt_crop_idle"
android:onClick="speechRecognitionClicked"
android:visibility="visible" />
</LinearLayout>
the soft-keyboard is open the moment the activity is on.
how can i force the text cursor appear and blink?
nowadays it doesn't appear even after the user clicks in this editText.
I have added <requestFocus /> but it didn't help
this is my code:
#Override
public void onResume() {
super.onResume();
if (type==AddressItem.FAVORITE_ITEM_EMPTY) {
new Handler().postDelayed(new Runnable() {
#Override
public void run() {
searchBox.requestFocus();
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
mgr.showSoftInput(searchBox, InputMethodManager.SHOW_FORCED);
}
}, 100);
}
}
You can try, To show cursor in editText, just use
android:textCursorDrawable="#null"
android:textColor="#color/someColor"
PS: Color is an optional but incase if you want to change color of cursor you can change it.
android:textCursorDrawable="#drawable/my_cursor"
Try
searchBox.setSelection(0);