Obsolete
Status Update
Comments
br...@gmail.com <br...@gmail.com> #2
[Comment deleted]
br...@gmail.com <br...@gmail.com> #3
I have spent more than two days on this problem. While removing the "layout_gravity" statement does help the cut off issue, I was unable to center anything in the linear layout that was smaller than the screen size. The item would always be left aligned. Ultimately what worked for me, which in my opinion is a hack, was to have the scrollview on top of a layout (in my case relativelayout) and centered. Then I had TWO linearlayouts cascaded as children on the scrollview. Also the height and width had to be set to "wrap_content" on the scrollview and linearlayouts. This is not the neatest solution, but I tried everything with no success. I event tried setting the gravity in code with "setlayoutparams()" if the objects were less than the screen size width. I hope this helps someone. I still think this is a BUG in Android and needs to be addressed by Google.
al...@gmail.com <al...@gmail.com> #4
I've noticed the same behaviour.
Any change you could post your updated Layout?
Many Thanks,
Al.
Any change you could post your updated Layout?
Many Thanks,
Al.
al...@gmail.com <al...@gmail.com> #5
I got what you meant:
<LinearLayout
android:id="@+id/footerWrapperLayoutToGetAroundCenteringIssue"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="center_horizontal">
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_height="fill_parent"
android:layout_width="wrap_content">
<LinearLayout
android:id="@+id/footerLayout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
Its just a pity when it centers them they are not evenly distributed.
<LinearLayout
android:id="@+id/footerWrapperLayoutToGetAroundCenteringIssue"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="center_horizontal">
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_height="fill_parent"
android:layout_width="wrap_content">
<LinearLayout
android:id="@+id/footerLayout"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
Its just a pity when it centers them they are not evenly distributed.
ko...@gmail.com <ko...@gmail.com> #6
I have the same problem. Child of HorizontalScrollView with gravity "center" are cutted
Here is my question on stackoverflow.http://stackoverflow.com/questions/13821384/strange-margins-in-horizontalscrollview
Here is my question on stackoverflow.
ko...@gmail.com <ko...@gmail.com> #7
Here is some code:
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
>
<Button
android:id="@+id/btn_add_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="clip_vertical"/>
</LinearLayout>
</HorizontalScrollView>
the button adds view in linear layout and then the views on the left side is cutted.
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<LinearLayout
android:id="@+id/container"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="center"
>
<Button
android:id="@+id/btn_add_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="clip_vertical"/>
</LinearLayout>
</HorizontalScrollView>
the button adds view in linear layout and then the views on the left side is cutted.
ls...@gmail.com <ls...@gmail.com> #8
Is the bug still open? I could not find a work around for it.
bo...@gmail.com <bo...@gmail.com> #9
so no one looked to this
li...@gmail.com <li...@gmail.com> #10
Comrades.
Use Soviet HorizontalScrollView instead.
Is very good.
Is never break down.
-------------
import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
public class SovietHorizontalScrollView extends HorizontalScrollView
{
public SovietHorizontalScrollView(Context context)
{
super(context);
}
public SovietHorizontalScrollView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public SovietHorizontalScrollView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if(getChildCount() > 0 && getChildAt(0) instanceof ViewGroup)
{
ViewGroup view = (ViewGroup) getChildAt(0);
int gravity = ((LayoutParams)view.getLayoutParams()).gravity;
if(gravity == Gravity.CENTER || gravity == Gravity.CENTER_HORIZONTAL)
{
if(view.getMeasuredWidth() > getMeasuredWidth())
{
LayoutParams params = (LayoutParams) view.getLayoutParams();
view.setLayoutParams(new LayoutParams(params.width, params.height, Gravity.NO_GRAVITY));
}
}
}
}
}
Use Soviet HorizontalScrollView instead.
Is very good.
Is never break down.
-------------
import android.content.Context;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.ViewGroup;
import android.widget.HorizontalScrollView;
public class SovietHorizontalScrollView extends HorizontalScrollView
{
public SovietHorizontalScrollView(Context context)
{
super(context);
}
public SovietHorizontalScrollView(Context context, AttributeSet attrs)
{
super(context, attrs);
}
public SovietHorizontalScrollView(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if(getChildCount() > 0 && getChildAt(0) instanceof ViewGroup)
{
ViewGroup view = (ViewGroup) getChildAt(0);
int gravity = ((LayoutParams)view.getLayoutParams()).gravity;
if(gravity == Gravity.CENTER || gravity == Gravity.CENTER_HORIZONTAL)
{
if(view.getMeasuredWidth() > getMeasuredWidth())
{
LayoutParams params = (LayoutParams) view.getLayoutParams();
view.setLayoutParams(new LayoutParams(params.width, params.height, Gravity.NO_GRAVITY));
}
}
}
}
}
ja...@gmail.com <ja...@gmail.com> #11
In the SovietHorizontalScrollView implementation the gravity constants (e.g. Gravity.CENTER) are bits, so shouldn't the conditional be:
if (gravity & Gravity.CENTER || gravity & Gravity.CENTER_HORIZONTAL)
???
if (gravity & Gravity.CENTER || gravity & Gravity.CENTER_HORIZONTAL)
???
ja...@gmail.com <ja...@gmail.com> #12
Also we may not want to strip gravity constants *besides* CENTER_HORIZONTAL. Here's my final onMeasure() method that retains non-horizontal gravity information:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (getChildCount() <= 0 || getChildAt(0) instanceof ViewGroup != true)
return;
final ViewGroup view = (ViewGroup) getChildAt(0);
if (view.getMeasuredWidth() <= getMeasuredWidth())
return;
final LayoutParams params = (LayoutParams) view.getLayoutParams();
view.setLayoutParams(new LayoutParams(params.width, params.height, params.gravity & ~Gravity.CENTER_HORIZONTAL));
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
if (getChildCount() <= 0 || getChildAt(0) instanceof ViewGroup != true)
return;
final ViewGroup view = (ViewGroup) getChildAt(0);
if (view.getMeasuredWidth() <= getMeasuredWidth())
return;
final LayoutParams params = (LayoutParams) view.getLayoutParams();
view.setLayoutParams(new LayoutParams(params.width, params.height, params.gravity & ~Gravity.CENTER_HORIZONTAL));
}
en...@google.com <en...@google.com>
el...@gmail.com <el...@gmail.com> #13
an...@gmail.com <an...@gmail.com> #14
I starred this issue in January 2012, and I am sad to see that it still has not been resolved. The only thing that has happened is that the status of the issue has become "obsolete"...which is not fair since the bug is still there.
da...@gmail.com <da...@gmail.com> #15
Over 3 years later and still no proper solution it seems. Would be nice to see this get resolved.
rs...@gmail.com <rs...@gmail.com> #16
#9 good!!!
si...@gmail.com <si...@gmail.com> #17
And the issue is still there as of April 2017...
ur...@gmail.com <ur...@gmail.com> #18
Im having this issue in December 2018 lol
in...@gmail.com <in...@gmail.com> #19
Welcome to the end of 2020, issue still exists ;)
se...@mrblue.com <se...@mrblue.com> #20
Comment has been deleted.
se...@zonesoft.org <se...@zonesoft.org> #21
Why is this still not fixed? Is there a workarround?
Thanks.
Thanks.
tu...@gmail.com <tu...@gmail.com> #22
Covid-19 Outbreaks comes to an end, but still the issue exists in 2023 :)
pa...@outlook.com <pa...@outlook.com> #23
Hello from 2024, another great work of not-fixing from the Android team, well done.
ca...@gmail.com <ca...@gmail.com> #24
Hello from 2024! I just came across this issue in HorizontalScrollView... which I had to debug for hours, because the left most button won't show despite scrolling all the way to the left.
and thank you Android Team for making this as a Won't Fix, highly appreciated, 🤙
and thank you Android Team for making this as a Won't Fix, highly appreciated, 🤙
ca...@gmail.com <ca...@gmail.com> #25
for Anyone coming from the future <CURRENT_YEAR>, a quick solution is to make a parent view of the Horizontal Scroll View and have its gravity=center so the HorizontalScrollView itself is centered (and thus the the inner LinearLayout of the HorizontalScrollView) and in the LinearLayout set the children gravity to center (gravity=center) so yo won't have to deal with this buggy layout_gravity and come across this issue.
//The parent of this horizontal scroll view has its gravity set to center, makes the HorizontalScrollView to be centered.
<HorizontalScrollView
android:scrollbars="none"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" <!--centers whatever views you have inside your linear layout.
android:id="@+id/myViews"> <!--bunch of controls, centered.-->
</LinearLayout>
</HorizontalScrollView>
//The parent of this horizontal scroll view has its gravity set to center, makes the HorizontalScrollView to be centered.
<HorizontalScrollView
android:scrollbars="none"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center" <!--centers whatever views you have inside your linear layout.
android:id="@+id/myViews"> <!--bunch of controls, centered.-->
</LinearLayout>
</HorizontalScrollView>
Description
If initial width of inner layout is wider than HorizontalScrollView itself, then a portion of the inner layout at the left remains hidden forever, i. e. layout considers current position as scrollX == 0.
Example:
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<LinearLayout android:id="@+id/top_buttons"
android:layout_width="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- Lots of items -->
</LinearLayout>
</HorizontalScrollView>
howewer the same example would work as expected if we replace layout_gravity in inner container with gravity attribute in scroll view itself:
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal">
<LinearLayout android:id="@+id/top_buttons"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<!-- Lots of items -->
</LinearLayout>
</HorizontalScrollView>
Expected results:
first case works correctly and does not cut off views.
Reproduced on:
Nexus One, android 2.3.4
emulatour, android 2.3.3