android - 将 imageview 对齐到 listview 的末尾,当 listview 加载数据时 android

标签 android listview imageview refresh

我正在设计一个带有自定义布局的自定义 ListView 。因为当 ListView 完成从 Web 服务加载数据时,我需要将 Imageview 添加到 ListView 的末尾和上方 @+id/progressBar1

在这种情况下 listview.addFooterView(View v) 不能使用,因为我使用了来自第三方库的自定义 PullToRefreshListview Pull to refresh listview

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical" >

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

        <com.rb.library.ScrollingTextView
            android:id="@+id/txtTicker"
            style="@style/style_bottom_marque"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:visibility="gone"
            app:typeface="roboto_condensed" />

        <include
            android:id="@+id/pan_breaking_new"
            layout="@layout/breaking_news" />
    </LinearLayout>

    <View
        android:id="@+id/view1"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/lay_top"
        android:background="#ccc"
        android:paddingTop="2dip" />

    <com.devspark.robototextview.widget.RobotoTextView
        android:id="@+id/txt_title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/view1"
        android:layout_gravity="fill_horizontal"
        android:drawableRight="@drawable/ic_title_arrow"
        android:gravity="left|center_vertical"
        android:inputType="textCapWords"
        android:padding="5dip"
        android:text="@string/TITLE_TOP_NEWS"
        app:typeface="roboto_black" android:visibility="gone"/>

    <View
        android:id="@+id/view2"
        android:layout_width="fill_parent"
        android:layout_height="1dp"
        android:layout_below="@+id/txt_title"
        android:background="#ccc" />

    <com.handmark.pulltorefresh.library.PullToRefreshListView
        android:id="@+id/listView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"

        android:layout_below="@+id/view2"
        android:layout_margin="2dip"
        android:layout_marginBottom="0dp"
        android:layout_marginTop="0dp"
        android:divider="#cccccc"
        android:dividerHeight="1dp" />







    <com.devspark.robototextview.widget.RobotoTextView
        android:id="@+id/main_error"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_gravity="fill_horizontal"
        android:gravity="center_horizontal"
        android:padding="20dip"
        android:text="@string/INTERNET_ERR"
        android:visibility="gone"
        app:typeface="roboto_black" />

    <ImageView
        android:id="@+id/img_error"
        android:layout_below="@+id/main_error"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
         android:gravity="center_horizontal"
        android:contentDescription="Error"
        android:layout_centerInParent="true"
        android:visibility="gone"
        android:src="@drawable/ic_error" />

    <LinearLayout android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_above="@+id/progressBar1"
        android:layout_below="@+id/listView">

        <ImageView
            android:id="@+id/list_footer_image"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:adjustViewBounds="true"
            android:scaleType="centerCrop"
            android:src="@drawable/app_logo" 

            android:visibility="visible"/>

    </LinearLayout>

    <ProgressBar
        android:id="@+id/progressBar1"
        android:layout_width="25dip"
        android:layout_height="25dip"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true" />



</RelativeLayout>

HomFragment.java

public View onCreateView(LayoutInflater inflater, ViewGroup container,
            Bundle savedInstanceState) {

        View rootView = inflater.inflate(R.layout.listview_layout, container,false);
        View footer_image=inflater.inflate(R.layout.listview_image_footer, container,false);



            /* get theme webservice*/

        StrictMode.ThreadPolicy policy1 = new StrictMode.ThreadPolicy.Builder().permitAll().build();
        StrictMode.setThreadPolicy(policy1); 


        userFunction=new UserFunctions();

            //Breaking News Section
            slide = AnimationUtils.loadAnimation(getActivity(), R.anim.slidedown);
            fadeOut = AnimationUtils.loadAnimation(getActivity(), R.anim.fadeout);
            pan_breaking_new = (LinearLayout)rootView.findViewById(R.id.pan_breaking_new);
            //pan_breaking_new.setOnClickListener(this);    
            pan_breaking_new.setVisibility(8);

            btn_close= (ImageView) rootView.findViewById(R.id.btn_close);
            btn_close.setOnClickListener(this);
            img_share= (ImageView) rootView.findViewById(R.id.img_share);
            img_share.setOnClickListener(this);
            //END Breaking News Section

            //Ticker
            marque = (ScrollingTextView)rootView.findViewById(R.id.txtTicker);
            marque.setVisibility(8);
            //END ticker


            main_error = (TextView) rootView.findViewById(R.id.main_error);
            main_error.setText("Loading...");
            img_error = (ImageView) rootView.findViewById(R.id.img_error);
            img_error.setOnClickListener(this);


            progressBar1 = (ProgressBar) rootView.findViewById(R.id.progressBar1);
            progressBar1.setVisibility(8);



            //karthik
            refreshable_listView = (PullToRefreshListView) rootView.findViewById(R.id.listView);
            listView=refreshable_listView.getRefreshableView();
            listView.addFooterView(footer_image);
}

最佳答案

尝试更改此代码:

 View footer_image=inflater.inflate(R.layout.listview_image_footer, container,false);

有了这个:

 View footer_image=inflater.inflate(R.layout.listview_image_footer,null);

注意:这里的容器是引用 fragment xml,尝试将自定义页脚添加到包含在容器中的 ListView,因此将页脚的根值指定为 null 而不是容器

关于android - 将 imageview 对齐到 listview 的末尾,当 listview 加载数据时 android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26966363/

相关文章:

java - 如何从主类获取返回字符串

android - 使用 Glide 将图像加载到 ImageView 中,Uri 从 Intent 返回, Action 为 ACTION_GET_CONTENT

java - Android GridView 适配器

android - 为什么 Android 为图像分配的内存是我预期的两倍?

android - 当文本太长时防止按钮调整大小?

java - Android Robotium 排序测试器

android - 是否有任何自动重构工具可以生成独特的 android 应用程序?

android - 如何在 ListView 的特定位置添加分隔符?

javascript - jQuery Mobile ListView 按钮不可见

android - 是否可以在 ListView 中的项目位置显示上下文菜单?