android - 自定义 ListView 中进度条的相同长宽比

标签 android android-layout progress-bar

我有一个带有自定义行布局的 ListView 。在此自定义行中有一个进度条(“圆”),指示加载状态。为了使布局看起来像我喜欢的那样,我使用layout_weight作为进度条和包含其他一些GUI内容的布局。

示例:

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleSmall"
    android:layout_width="0dip" 
    android:layout_height="match_parent" 
    android:layout_weight="1" />


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="0dip" 
    android:layout_height="match_parent" 
    android:layout_weight="7"
    android:layout_marginLeft="6dip" 
    android:orientation="vertical"
    >

我希望进度条具有相同的宽高比。

我的问题是进度条在不同设备上看起来很奇怪。在我的 Galaxy Nexus 上,一切看起来都很好,并且进度条具有相同的纵横比。但是在 - 例如 - 我的模拟器上,进度条看起来像一个鸡蛋,这太糟糕了。

有人可以指出我的错误吗?

编辑:

我不使用wrap_content,因为布局将使用进度条的宽度来显示 View 的其余部分,这真的很小(然后就没有地方放置文本了)。

编辑2:

两张图片显示问题:

“蛋” http://s14.directupload.net/file/d/2955/89xvdhrz_png.htm

wrap_content 的用法 http://s1.directupload.net/file/d/2955/sryrhkkk_png.htm

编辑3:

CFlex 的方法。整个 xml 文件

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
android:orientation="horizontal">

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleSmall"
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_gravity="center"
    android:layout_margin="4dp"/>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="0dip" 
    android:layout_height="match_parent" 
    android:layout_weight="7"
    android:layout_marginLeft="6dip" 
    android:orientation="vertical"
    >

    <TextView 
        android:id="@android:id/text1" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearanceLarge"/>

    <TextView 
        android:id="@android:id/text2" 
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content" 
        android:textAppearance="?android:attr/textAppearanceSmall"/>

</LinearLayout>

最佳答案

你为什么不尝试这样的事情:

<ProgressBar
    android:id="@+id/progressBar1"
    style="?android:attr/progressBarStyleSmall"
    android:layout_width="wrap_content" 
    android:layout_height="match_parent"  
    android:layout_gravity="center"
    android:layout_margin="4dp"/>


<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="0dp" 
    android:layout_height="match_parent" 
    android:layout_weight="1"
    android:layout_marginLeft="6dip" 
    android:orientation="vertical"
    >

假设您处于水平LinearLayout

告诉我这是否不起作用。

编辑:使用relativeLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">

    <ProgressBar
            android:id="@+id/progressBar1"
            style="?android:attr/progressBarStyleSmall"
            android:layout_width="wrap_content"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_centerVertical="true"
            android:layout_margin="4dp"/>

    <TextView
            android:id="@android:id/text1"
            android:layout_toRightOf="@+id/progressBar1"
            android:layout_alignParentTop="true"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceLarge"/>

    <TextView
            android:layout_toRightOf="@+id/progressBar1"
            android:layout_below="@android:id/text1"
            android:id="@android:id/text2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textAppearance="?android:attr/textAppearanceSmall"/>

</RelativeLayout>

关于android - 自定义 ListView 中进度条的相同长宽比,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11543296/

相关文章:

android - 在 Android 中以编程方式实现 splitView

ios - 在 Realm 下载内容时如何更新 progressView

android - java.io.IOException : Cannot find PROCESSED_RES output for Main [Dynamic Feature Module] 异常

java - 在 Android 中设置委托(delegate)

android - 我可以在 Kotlin 中对 Room 和 API 调用使用相同的数据类吗?

Android背景图片填满屏幕

Android Fragment 不显示在大布局上

android - cursor.setNotificationUri() 是做什么用的?

java - 如何在java中显示一个工作但虚拟的进度条

reactjs - react MUI : Create stacked progress bar by disabling buffer animation