【问题标题】:Footer inflate not working on landscape Android页脚膨胀不适用于横向 Android
【发布时间】:2014-06-05 00:39:32
【问题描述】:

我在使用页脚时遇到了一些尴尬的问题。 我有一个在页面中加载的自定义项目列表。当您到达最后一个项目时,它会检索更多可用的项目,即(在等待时)页脚膨胀说“正在下载”。当然,在项目下载后它会被删除。 问题是我膨胀页脚的方式只能在肖像模式下正常工作。使用横向时,页脚不会出现。

编辑:问题是在活动中更改模式(风景、肖像)时。如果我从一开始就以横向开始,它也可以。

这是我用来膨胀页脚的代码:

lv = (ListView) findViewById(R.id.shops_list);
footerView = getLayoutInflater().inflate(R.layout.footer_downloading, null, false);
lv.addFooterView(footerView);

这是布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".ListActivity"
android:background="@color/background" >

    <ProgressBar android:indeterminate="true"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:id="@+id/progress_list" 
            style="?android:attr/progressBarStyle"
            android:layout_centerHorizontal="true"
            android:layout_centerVertical="true"
            android:indeterminateBehavior="cycle" />

    <LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:visibility="gone"
    android:id="@+id/generic_shops_list"
    android:background="@color/background" >

       <ListView
        android:id="@+id/shops_list"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:divider="@color/pallette_blue"
        android:dividerHeight="1dp" />

    </LinearLayout>

</RelativeLayout>

这是页脚:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="15dip" >

    <TextView
        android:id="@+id/message_downloading_more"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:fontFamily="sans-serif-light"
        android:text="@string/downloading_more"
        android:textSize="22sp"
        android:textStyle="bold"
        android:clickable="false"
        android:layout_centerInParent="true" />

    <ProgressBar android:indeterminate="true"
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content"
            android:id="@+id/progress_downloading" 
            style="?android:attr/progressBarStyle"
            android:indeterminateBehavior="cycle"
            android:layout_centerVertical="true"
            android:layout_toLeftOf="@id/message_downloading_more"
            android:layout_marginLeft="15dip" />


</RelativeLayout>

这是完整的课程,也可以参考:Class

【问题讨论】:

    标签: android android-layout footer layout-inflater landscape-portrait


    【解决方案1】:

    在膨胀视图时,您应该始终指定父布局。

    footerView = getLayoutInflater().inflate(R.layout.footer_downloading, lv, false);
    

    【讨论】:

    • 仍然崩溃...除此之外,这并不能解释为什么它已经在 potrait 上工作,但在风景上却没有
    • 崩溃?我可以看到堆栈跟踪吗?
    • 实际上它并没有在那里崩溃...当我在下载完成后删除它时它崩溃了,当然页脚从未膨胀。但是充气并没有崩溃,它只是无法正常工作。
    • 啊,你在哪里添加页脚?开始下载时会调用它吗?您需要记住在重新创建整个 UI 时在下载运行时旋转时重新添加它。
    • 我在这里上传了完整的课程以供更多参考link
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-02-23
    相关资源
    最近更新 更多