Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了android – 当Horizo​​ntalScrollView的中心元素不足以使其滚动时大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个带有Horizo​​ntalScrollView的Layout,其中包含一个用于菜单内容的LinearLayout,其中内容被DB的内容膨胀.这样做很好,但是当没有足够的元素使HSV滚动时,它不会填满理想地应该居中的屏幕的宽度.即
目前:
| Element 1 Element 2                         | <- edge of screen

代替:

|        Element 1            Element 2       | <- edge of screen

同时仍然能够:

| Element 1 Element 2 Element 3 Element 4 Elem| <- edge of screen Now scrolling

布局XML是:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://scheR_317_11845@as.android.com/apk/res/android"
    android:id="@+id/mainLinearLayout"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <TextView 
         android:id="@+id/header"
         android:layout_width="fill_parent"
         android:layout_height="25dp" >
    </TextView>

    <ScrollView
         android:id="@+id/scroll1"
         android:layout_width="fill_parent"
         android:layout_height="fill_parent"
         android:layout_weight="1" >

        <LinearLayout
             android:id="@+id/contentLayout"
             android:layout_width="fill_parent"
             android:layout_height="wrap_content"
             android:orientation="vertical" >

        </LinearLayout>
    </ScrollView>

    <horizontalscrollview
        android:id="@+id/horizontalscrollview1"
        android:layout_width="fill_parent"
        android:layout_height="30dp">

        <LinearLayout
            android:id="@+id/footerLayout"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="horizontal" >

        </LinearLayout>
   </horizontalscrollview>
</LinearLayout>

下面的XML被充满footerLayout:

<?xml version="1.0" encoding="utf-8"?>

        <TextView
            xmlns:android="http://scheR_317_11845@as.android.com/apk/res/android"
            android:id="@+id/footer_content"
            android:textSize="18sp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:paddingLeft="5dp"
            android:paddingRight="5dp"
            android:text="FOOTER"
            android:singleLine="true" />

任何帮助将不胜感激.

解决方法

我刚刚解决了这个问题.几分钟前我碰到了.您需要将Horizo​​ntalScrollView居中并将其宽度/高度设置为wrap_content.您放在HSV中的布局必须将其宽度/高度设置为包装内容.这里的重要部分是不要在这个布局上设置任何重力/ layout_gravity,或者在你的意见膨胀之后可能会遇到(非常烦人的)裁剪问题.下面的例子包含在RelativeLayout中.
<horizontalscrollview  android:id="@+id/svExample"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_centerHorizontal="true"
    android:layouT_Below="@id/rlExample">
    <LinearLayout
        android:id="@+id/llExample"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
    </LinearLayout>
</horizontalscrollview >

大佬总结

以上是大佬教程为你收集整理的android – 当Horizo​​ntalScrollView的中心元素不足以使其滚动时全部内容,希望文章能够帮你解决android – 当Horizo​​ntalScrollView的中心元素不足以使其滚动时所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。