Text on textview is cliping on half on animation Android - java

So my problem is, I use animation to resize text in text view and move it a bit. When I resize the LinearLayout Layout text is clipping to half if it's long text how can I stay in bound so to not clip my text when I resize the LinearLayout
Text view is in Liner layout and parent is Constrant layout.
<LinearLayout
android:id="#+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#id/cons1">
<TextView
android:id="#+id/t1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="10dp"
android:fontFamily="#font/poppins"
android:text="How to make french toast"
android:textColor="#color/black"
android:textSize="25sp"
android:textStyle="bold"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toBottomOf="#id/cons1" />
</LinearLayout>
Scroll view listener to change on scrolling
scrollView.setOnScrollChangeListener(new View.OnScrollChangeListener() {
boolean isStart = false;
#Override
public void onScrollChange(View v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) {
if (scrollY > 0 && !isStart) {
recipeTitle.startAnimation(animZoomOut);
slideView(layout2, layout2.getHeight(), layout2.getHeight() / 2);
isStart = true;
} else if (scrollY <= 0) {
slideView(layout2, layout2.getHeight(), layout2.getHeight() * 2);
recipeTitle.startAnimation(animZoomIn);
isStart = false;
}
}
});
Method to resize textview,
public static void slideView(View view,
int currentHeight,
int newHeight) {
ValueAnimator slideAnimator = ValueAnimator
.ofInt(currentHeight, newHeight)
.setDuration(1000);
/* We use an update listener which listens to each tick
* and manually updates the height of the view */
slideAnimator.addUpdateListener(animation1 -> {
Integer value = (Integer) animation1.getAnimatedValue();
view.getLayoutParams().height = value.intValue();
view.requestLayout();
});
/* We use an animationSet to play the animation */
AnimatorSet animationSet = new AnimatorSet();
animationSet.setInterpolator(new AccelerateDecelerateInterpolator());
animationSet.play(slideAnimator);
animationSet.start();
}
anim xml files
<set xmlns:android="http://schemas.android.com/apk/res/android"
android:fillAfter="true">
<scale
xmlns:android="http://schemas.android.com/apk/res/android"
android:duration="1000"
android:fromXScale="1.0"
android:fromYScale="1.0"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="0.5"
android:toYScale="0.5">
</scale>
<translate xmlns:android="http://schemas.android.com/apk/res/android"
android:fromXDelta="0%p" android:fromYDelta="0%p"
android:toXDelta="-28%p" android:toYDelta="-28%p"
android:duration="1000"
android:fillAfter="true" />

Related

Android: how can I rotate image and set it filling fragment?

I have a fragment that displays some images on 30% of the screen. In case when image.height is bigger than image.width, I wanted to rotate the image 90 degrees. However, after that operation, the image does not fully fill the fragment - "new" width after rotation matches previous height, so the image occupies only some part in the middle of the fragment. How can I make it a matching fragment? What I'm doing wrong or missing?
This is how it looks like without rotation:
This is after rotation:
And that's what I want to have:
Here is the code:
#Override
public void onViewCreated(#NonNull View view, Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
setImageFittedToDisplay(view);
}
public void setImageFittedToDisplay(View view) {
int height = getDisplayMetrics().heightPixels;
ViewGroup.LayoutParams params = view.getLayoutParams();
params.height = ((Double) (height * 0.3)).intValue();
view.setLayoutParams(params);
ImageView image = view.findViewById(R.id.picture);
image.setDrawingCacheEnabled(true);
int w = image.getDrawable().getIntrinsicWidth();
int h = image.getDrawable().getIntrinsicHeight();
if(h > w) {
image.setRotation(90f);
}
ViewGroup.LayoutParams imageParams = image.getLayoutParams();
imageParams.height = ActionBar.LayoutParams.WRAP_CONTENT;
imageParams.width = ActionBar.LayoutParams.WRAP_CONTENT;
image.setLayoutParams(imageParams);
}
and here is .xml of the fragment:
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/APOD_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
xmlns:app="http://schemas.android.com/apk/res-auto">
<ImageView
android:id="#+id/picture"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/cool_pic"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<View
android:id="#+id/separator"
android:layout_width="match_parent"
android:layout_height="10dp"
android:background="#color/colorSeparator"
app:layout_constraintBottom_toBottomOf="#+id/picture"
app:layout_constraintTop_toBottomOf="#+id/picture" />
</androidx.constraintlayout.widget.ConstraintLayout>

Expand and collapse Relativelayout by button click

I have this RelativeLayout which expand and collapse on button click
it works fine on one button.
I want to reuse same method on more two RelativeLayout
in same layout
and expand using other two buttons.
This code is running fine. just want more layout to do same action.
Layout:
This is my code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="none">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="64dp"
android:background="#FFF"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title"
android:textSize="20sp" />
<Button
android:id="#+id/viewmore"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_marginLeft="280dp"
android:background="#null"
android:text="viewmore" />
</RelativeLayout>
<RelativeLayout
android:visibility="gone"
android:id="#+id/expandable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:animateLayoutChanges="true"
android:background="#color/colorAccent"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="133dp"
android:text="Text messaging, or texting, is the act of composing and sending electronic messages, typically consisting of alphabetic and numeric characters"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="#+id/textView4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title 2"
android:textSize="20sp" />
<Button
android:id="#+id/viewmore1"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_marginLeft="280dp"
android:background="#null"
android:text="viewmore" />
</RelativeLayout>
<RelativeLayout
android:visibility="gone"
android:animateLayoutChanges="true"
android:id="#+id/expandable1"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="30dp"
android:background="#color/colorPrimary">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text messaging, or texting, is the act of composing and sending electronic messages, typically consisting of alphabetic and numeric characters"
android:textSize="20sp" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title 3"
android:textSize="20sp" />
<Button
android:id="#+id/viewmore2"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_marginLeft="280dp"
android:background="#null"
android:text="viewmore" />
</RelativeLayout>
<RelativeLayout
android:visibility="gone"
android:animateLayoutChanges="true"
android:id="#+id/expandable2"
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_marginTop="30dp"
android:background="#color/colorPrimary">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Text messaging, or texting, is the act of composing and sending electronic messages, typically consisting of alphabetic and numeric characters"
android:textSize="20sp" />
</RelativeLayout>
</LinearLayout>
</ScrollView>
Source Code:
RelativeLayout relativeLayout, relativeLayout1, relativeLayout2;
Button viewmore, viewmore1, viewmore2;
ValueAnimator mAnimator;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewmore);
relativeLayout = (RelativeLayout) findViewById(R.id.expandable);
relativeLayout1 = (RelativeLayout) findViewById(R.id.expandable1);
relativeLayout2 = (RelativeLayout) findViewById(R.id.expandable2);
viewmore = (Button) findViewById(R.id.viewmore);
viewmore1 = (Button) findViewById(R.id.viewmore1);
viewmore2 = (Button) findViewById(R.id.viewmore2);
viewmore.setOnClickListener(this);
viewmore1.setOnClickListener(this);
viewmore2.setOnClickListener(this);
relativeLayout.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
#Override
public boolean onPreDraw() {
relativeLayout.getViewTreeObserver().removeOnPreDrawListener(this);
relativeLayout.setVisibility(View.GONE);
final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
relativeLayout.measure(widthSpec, heightSpec);
mAnimator = slideAnimator(0, relativeLayout.getMeasuredHeight());
return true;
}
});
}
private void expand() {
relativeLayout.setVisibility(View.VISIBLE);
mAnimator.start();
}
private void collapse() {
int finalHeight = relativeLayout.getHeight();
ValueAnimator mAnimator = slideAnimator(finalHeight, 0);
mAnimator.addListener(new Animator.AnimatorListener() {
#Override
public void onAnimationEnd(Animator animator) {
//Height=0, but it set visibility to GONE
relativeLayout.setVisibility(View.GONE);
}
#Override
public void onAnimationStart(Animator animator) {
}
#Override
public void onAnimationCancel(Animator animator) {
}
#Override
public void onAnimationRepeat(Animator animator) {
}
});
mAnimator.start();
}
private ValueAnimator slideAnimator(int start, int end) {
ValueAnimator animator = ValueAnimator.ofInt(start, end);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
//Update Height
int value = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = relativeLayout.getLayoutParams();
layoutParams.height = value;
relativeLayout.setLayoutParams(layoutParams);
}
});
return animator;
}
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.viewmore:
if (relativeLayout.getVisibility() == View.GONE) {
expand();
} else {
collapse();
}
break;
case R.id.viewmore1:
break;
case R.id.viewmore2:
break;
}
}
To continue with your approach, you will have to make the code apply to all three sections that you have laid out. To do this, you will need to change several of your methods to accept a RelativeLayout as an argument.
First, in your onClick listener, fill in the case blocks so each block calls expand() with the targeted RelativeLayout and maximum height. Call collapse() with the targeted RelativeLayout. You will then need to modify expand() and collapse() to handle the new arguments:
You will notice in the following code that I have changed how and where the animator is created. The animator will need to work with each RelativeLayout.
So, onClick() calls expand() which calls slideAnimator(). For each call, the RelativeLayout that is effected is passed as an argument. In this way, you can generalize the code to work with more than one RelativeLayout.
The pre-draw listener will also need to measure each expandable RelativeLayout.
Here is it all put together:
MainActivity.xml
public class MainActivity extends AppCompatActivity
implements View.OnClickListener {
RelativeLayout relativeLayout, relativeLayout1, relativeLayout2;
Button viewmore, viewmore1, viewmore2;
int height, height1, height2;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.viewmore);
relativeLayout = (RelativeLayout) findViewById(R.id.expandable);
relativeLayout1 = (RelativeLayout) findViewById(R.id.expandable1);
relativeLayout2 = (RelativeLayout) findViewById(R.id.expandable2);
viewmore = (Button) findViewById(R.id.viewmore);
viewmore1 = (Button) findViewById(R.id.viewmore1);
viewmore2 = (Button) findViewById(R.id.viewmore2);
viewmore.setOnClickListener(this);
viewmore1.setOnClickListener(this);
viewmore2.setOnClickListener(this);
relativeLayout.getViewTreeObserver().addOnPreDrawListener(
new ViewTreeObserver.OnPreDrawListener() {
#Override
public boolean onPreDraw() {
relativeLayout.getViewTreeObserver().removeOnPreDrawListener(this);
relativeLayout.setVisibility(View.GONE);
relativeLayout1.setVisibility(View.GONE);
relativeLayout2.setVisibility(View.GONE);
final int widthSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
final int heightSpec = View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED);
relativeLayout.measure(widthSpec, heightSpec);
height = relativeLayout.getMeasuredHeight();
relativeLayout1.measure(widthSpec, heightSpec);
height1 = relativeLayout.getMeasuredHeight();
relativeLayout2.measure(widthSpec, heightSpec);
height2 = relativeLayout.getMeasuredHeight();
return true;
}
});
}
private void expand(RelativeLayout layout, int layoutHeight) {
layout.setVisibility(View.VISIBLE);
ValueAnimator animator = slideAnimator(layout, 0, layoutHeight);
animator.start();
}
private void collapse(final RelativeLayout layout) {
int finalHeight = layout.getHeight();
ValueAnimator mAnimator = slideAnimator(layout, finalHeight, 0);
mAnimator.addListener(new Animator.AnimatorListener() {
#Override
public void onAnimationEnd(Animator animator) {
//Height=0, but it set visibility to GONE
layout.setVisibility(View.GONE);
}
#Override
public void onAnimationStart(Animator animator) {
}
#Override
public void onAnimationCancel(Animator animator) {
}
#Override
public void onAnimationRepeat(Animator animator) {
}
});
mAnimator.start();
}
private ValueAnimator slideAnimator(final RelativeLayout layout, int start, int end) {
ValueAnimator animator = ValueAnimator.ofInt(start, end);
animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
#Override
public void onAnimationUpdate(ValueAnimator valueAnimator) {
//Update Height
int value = (Integer) valueAnimator.getAnimatedValue();
ViewGroup.LayoutParams layoutParams = layout.getLayoutParams();
layoutParams.height = value;
layout.setLayoutParams(layoutParams);
}
});
return animator;
}
#Override
public void onClick(View view) {
switch (view.getId()) {
case R.id.viewmore:
if (relativeLayout.getVisibility() == View.GONE) {
expand(relativeLayout, height);
} else {
collapse(relativeLayout);
}
break;
case R.id.viewmore1:
if (relativeLayout1.getVisibility() == View.GONE) {
expand(relativeLayout1, height1);
} else {
collapse(relativeLayout1);
}
break;
case R.id.viewmore2:
if (relativeLayout2.getVisibility() == View.GONE) {
expand(relativeLayout2, height2);
} else {
collapse(relativeLayout2);
}
break;
}
}
}
You can also create own custom expandable which extend android relative layout. On that custom view you can store expanded or collapsed status. As well as you can create custom attributes for define your view default status like expanded or collapsed. So you don't need to compare view status you will just call your toggle function which toggle your view expanded to collapse or vice versa
If you want to show collapsed view as a default view you should not change view visibility before onMeasure function and store your view measured height. If you change visibility on view constructor onMeasure function skip calculation for that view. You should toggle visibility on onPreDraw function.

Wrap content not working for dialog

My goal is to create a dialog that wraps its content height as shown in the image below.
My problem is that my dialog wants to match its parent as shown in the image below. The height should stop at the item "asdf" and this white space below "asdf" should not exist.
This is my code for the later:
private void showPopupEventTest(final String Cardid) {
Dialog dialog = new Dialog(getActivity(), R.style.Theme_AppCompat_Dialog_Alert);
dialog.getWindow().setLayout(WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT);
dialog.setContentView(R.layout.fragment_event);
SwipeRefreshLayout swipeRefreshLt = (SwipeRefreshLayout) dialog.findViewById(R.id.swipeRefreshLt);
ListView lv = (ListView) dialog.findViewById(R.id.Contacts_list_view);
SearchView SearchET = (SearchView) dialog.findViewById(R.id.SearchET);
LinearLayout layoutLinearLayout = (LinearLayout) dialog.findViewById(R.id.layoutLinearLayout);
EventAdaptor myAdapter = new EventAdaptor(getContext(), ArrayList_EventObject);
lv.setAdapter(myAdapter);
dialog.getWindow().setSoftInputMode(
WindowManager.LayoutParams.SOFT_INPUT_STATE_HIDDEN);
dialog.show();
}
And this is the layout:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/layoutLinearLayout"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp">
<SearchView
android:id="#+id/SearchET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:iconifiedByDefault="false" />
<android.support.v4.widget.SwipeRefreshLayout
android:layout_width="match_parent"
android:id="#+id/swipeRefreshLt"
android:layout_height="wrap_content">
<ListView
android:id="#+id/Contacts_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.v4.widget.SwipeRefreshLayout>
</LinearLayout>
What am I doing wrong?
try this
Window window = customDialog.getWindow();
window.setLayout(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.WRAP_CONTENT);
window.setGravity(Gravity.CENTER);
customDialog.show();
There are two options for you
Use RecyclerView instead of ListView
OR
use below code after setting the adapter.
public static void setListViewHeightBasedOnChildren(ListView listView) {
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
// pre - condition
return;
}
int totalHeight = 0;
for (int i = 0; i < listAdapter.getCount(); i++) {
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = listView.getLayoutParams();
params.height = totalHeight + (listView.getDividerHeight() * (listAdapter.getCount() - 1));
listView.setLayoutParams(params);
listView.requestLayout();
}
Your problem is in your xml layout. Try this:
<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="#+id/layoutLinearLayout"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:paddingTop="8dp">
<SearchView
android:id="#+id/SearchET"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:iconifiedByDefault="false" />
<!--<android.support.v4.widget.SwipeRefreshLayout-->
<!--android:layout_width="match_parent"-->
<!--android:id="#+id/swipeRefreshLt"-->
<!--android:layout_height="wrap_content">-->
<ListView
android:id="#+id/Contacts_list_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<!--</android.support.v4.widget.SwipeRefreshLayout>-->
</LinearLayout>
Explanation:
The problem was the SwipeRefreshLayout. I commented it

GridView scrolling ends at half the screen when translated

Whatever i do i cant get this to work. I have a method to set the layout for the header of the view (which really is the whole view)...
private KenBurnsSupportView mHeaderSupportView;
private View mHeader;
private int mMinHeaderHeight;
private int mHeaderHeight;
private int mMinHeaderTranslation;
private int mActionBarHeight;
private boolean mResised = false;
private void setHeader(View fragmentView) {
mMinHeaderHeight = getResources().getDimensionPixelSize(R.dimen.min_header_height);
mHeaderHeight = getResources().getDimensionPixelSize(R.dimen.header_height);
mActionBarHeight = mUtils.getActionBarHeight(mActionBarHeight);
mMinHeaderTranslation = -mMinHeaderHeight + mActionBarHeight;
mHeaderSupportView = (KenBurnsSupportView) fragmentView.findViewById(R.id.song_header_support_view);
mHeader = fragmentView.findViewById(R.id.song_header);
mHeaderSupportView.setImageViews(mPlayList.getPlImageView(), mPlayList.getPlSongs().get(0).getmImageView());
}
This uses this view :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:widget="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/song_header"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:transitionName="MyTransition"
android:layout_width="match_parent"
android:layout_height="#dimen/header_height"
android:id="#+id/pl_artwork"
android:scaleType="centerCrop"
android:src="#drawable/ic_user_background"
android:tint="#color/colorPrimary40Transparent"/>
<TextView
android:id="#+id/pl_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="#string/pl_title_str"
android:padding="16dp"
android:textSize="24sp"
android:textColor="#FFFFFF"
android:maxLines="1"
android:ellipsize="end"
android:layout_gravity="end"
android:layout_alignBottom="#+id/pl_artwork"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<GridView
android:id="#+id/song_grid_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="150dp"
android:numColumns="2"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="3dp"
android:paddingStart="3dp"
android:paddingEnd="1dp"
android:paddingBottom="1dp"
android:layout_marginTop="#dimen/header_height"
android:horizontalSpacing="1dp"
android:verticalSpacing="1dp"
android:stretchMode="none"/>
<View
android:layout_below="#id/pl_artwork"
android:layout_width="fill_parent"
android:layout_height="5dip"
android:background="#drawable/drop_shadow"/>
<com.android.APPPACKEGE.widgets.CircleButton
android:id="#+id/song_play_fab"
widget:circle_icon="#android:drawable/ic_media_play"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
widget:circle_color="#color/colorPrimary"
android:layout_gravity="end"
android:padding="16dp"
android:layout_marginEnd="44dp"
android:layout_marginRight="44dp"
android:layout_marginTop="160dp"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<com.android.APPPACKEGE.ui.songheaderlib.KenBurnsSupportView
android:id="#+id/song_header_support_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"/>
</RelativeLayout>
What ever i do i cant get the gridView to end its view at the bottom of the device :
![Scroll ends at somewhat half of the screen][1]
http://i.stack.imgur.com/lBKiA.gif
Here is the onScroll part where all of it happens:
public void onScroll(AbsListView view, int firstVisibleItem, int visibleItemCount, int totalItemCount) {
int scrollY = mUtils.getScrollY(view, mHeaderHeight);
ViewHelper.setTranslationY(mHeader, Math.max(-scrollY, mMinHeaderTranslation));
And heres the getScrollY method:
public int getScrollY(AbsListView view, int mHeaderHeight) {
View c = view.getChildAt(0);
if (c == null) {
return 0;
}
int firstVisiblePosition = view.getFirstVisiblePosition();
int top = c.getTop();
int headerHeight = 0;
if (firstVisiblePosition >= 1) {
headerHeight = mHeaderHeight;
}
return (-top + firstVisiblePosition * c.getHeight() + headerHeight) + 48;
}
I have tryed everything, even setting a fixed 770dp (570 screen size + the header 200dp size) on all the parents of the gridView. That didnt work...
What am i doing wrong?

does not work ViewFlipper

sorry for my english. When the picture to fill the screen, I want to do that could be used to scroll. To do this, use ViewFlipper. but it does not work. is the class that displays images in full screen. What am I doing wrong?
public class FullScreenImage extends Activity implements OnTouchListener{
private ViewFlipper flipper = null;
private float fromPosition;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.full_screen);
Intent intent = getIntent();
long imageId = intent.getExtras().getLong(FullScreenImage.class.getName());
LinearLayout mainLayout = (LinearLayout) findViewById(R.id.main_layout);
flipper = (ViewFlipper) findViewById(R.id.fullImage);
flipper.setOnTouchListener(this);
ImageView imageView = (ImageView) findViewById(R.id.imageView1);
imageView.setLayoutParams( new ViewFlipper.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
imageView.setImageResource((int) imageId);
}
public boolean onTouch(View view, MotionEvent event)
{
switch (event.getAction())
{
case MotionEvent.ACTION_DOWN:
fromPosition = event.getX();
break;
case MotionEvent.ACTION_UP:
float toPosition = event.getX();
if (fromPosition > toPosition)
flipper.showNext();
else if (fromPosition < toPosition)
flipper.showPrevious();
default:
break;
}
return true;
}
}
xml file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ViewFlipper
android:id="#+id/fullImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ViewFlipper>
</LinearLayout>
Your XML has but a single member within the flipper. The idea is to have two or items and the flipper will change between them. Add another image like this to your flipper
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/main_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ViewFlipper
android:id="#+id/fullImage"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</ViewFlipper>

Categories

Resources