簡體   English   中英

Android-在左上角顯示進度欄

[英]Android - display progress bar on top left corner

我目前正在嘗試在屏幕的左上角放置一個進度條。 但是,我不太確定哪種方法是最好的方法。 我應該以編程方式創建進度條,而不是在xml中創建進度條嗎? 還是應該更改布局? 謝謝。 下面的XML。

XML代碼:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/background"
    android:focusableInTouchMode="true"
    android:orientation="vertical" >

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="fill_parent"
        android:layout_height="53dp"
        android:layout_marginBottom="5dp"
        android:src="@raw/topbar" />

    <TextView
        android:id="@+id/search_nameOfFeed"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center_vertical|center_horizontal"
        android:text="Event Name"
        android:textColor="@color/black"
        android:textSize="18sp" >
    </TextView>

    <ListView
        android:id="@+id/searchfeed_view"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="0.83"
        android:dividerHeight="10.0sp"
        android:fadingEdge="none"
        android:stackFromBottom="false"
        android:transcriptMode="normal" >
    </ListView>

</LinearLayout>

您可以使用任何一種方式(以XML或以編程方式)創建它。 如果您是按比例創建的,則將引力設置為top,如果使用XML創建,則使用相對布局而不是線性布局,並使用android:layout_gravity =“ top | left”。 如果要顯示在中心,請點擊鏈接

要在特定區域中放置視圖時,布局的最佳選擇是FrameLayoutRelativeLayout

RelativeLayout允許您將每個視圖相對於彼此放置。 FrameLayout允許您以z-index位置堆疊視圖。

兩者一起玩,您可能會找到想要的結果。

在android中設計布局的最佳方法是通過以XML創建布局,因此您應該以XML進行布局。 您可以通過在ImageView之前添加ProgressBar來實現所需的功能

我懷疑這正是您正在尋找的東西,但是您可能想要實現非侵入式進度條的另一種方法是將其放在活動的標題欄中。 查看示例,了解如何執行此操作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM