2

I want to add progress bar in the middle of my image view. All components I need to add in code. This is code:

    ReloadableImageView imageView = null;   

    LayoutInflater inflater = getActivity().getLayoutInflater();
    for(PageInfo info: pagesInfo){
        if(!info.isVisible())
            continue;
        info.setThumbnail(path + "/" + info.getPageNum() + ".jpg");
        inflater.inflate(R.layout.cell, null);  
        imageView = new ReloadableImageView(getActivity());

            LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT,
                                                                        LinearLayout.LayoutParams.WRAP_CONTENT);
            lp.setMargins(10, 10, 10, 10);
            imageView.setLayoutParams(lp);

            imageView.setOnClickListener(clickListener);
            imageView.setId(info.getPageNum());  
            imageView.setBlur(info.requiresLogin());
            imageView.setImagePath(info.getThumbnail());
            views.append(info.getPageNum(), imageView);
            mainLayout.addView(imageView);  
        }  

How can I add progress bar to my image view in code? "mainLayout" is LinearLayout.

Edit:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/RelativeLayout1"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@android:color/transparent" >

    <HorizontalScrollView
        android:id="@+id/horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="true"
        android:background="#80000000" 
        >

        <LinearLayout
            android:id="@+id/_linearLayout"
            android:layout_height="wrap_content"
            android:layout_width="wrap_content"
            android:orientation="horizontal" >
        </LinearLayout>

    </HorizontalScrollView>

               <ProgressBar
                   android:id="@+id/progressBar1"
                   style="?android:attr/progressBarStyleLarge"
                   android:layout_width="wrap_content"
                   android:layout_height="wrap_content"
                   android:layout_alignParentBottom="true"
                   android:layout_centerHorizontal="true"
                   android:visibility="visible" />

</RelativeLayout>
4

1 回答 1

4

为此目的使用RelativeLayout。之后,您可以进行alignment调整以放置progressbar在上面ImageView

此外,如果您是动态添加 ImageView,也可以动态添加进度条。

下面是一个代码片段,它将 ImageView 上方的进度条设置为居中对齐:

<RelativeLayout
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"
    android:src="@drawable/image" />

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleHorizontal"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" 
    android:layout_centerInParent="true"/>
</RelativeLayout>
于 2013-05-23T12:12:06.307 回答