【发布时间】:2012-07-18 14:07:26
【问题描述】:
我有一个带有自定义行布局的列表视图。在这个自定义行中是一个进度条(“圆圈”),它指示加载状态。为了使布局看起来像我喜欢的那样,我使用 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,因为布局将在视图的其余部分使用进度条的宽度,这真的很小(然后就没有文本的地方了)。
编辑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>
【问题讨论】:
-
为什么不使用包装内容而不是在进度条中提供 match_parent 和 0dip
-
编辑了我的问题。不能使用 wrap_content 因为我的布局会被破坏。
-
您可以将样式设置为进度条,如小、正常和大。例如style="?android:attr/progressBarStyleSmall"
-
谢谢,我试过了。没有“progressBarStyleNormal”资源。小,高度用于整行布局(见图二),太小了。大它看起来也很糟糕。也许我对这种布局的方法是完全错误的?
-
如果您使用 LinearLayout 代替进度条 - 具有所需的尺寸 - 然后将带有
wrap_content的进度条放置在该布局内?我认为它应该可以解决问题:布局的显式尺寸将确保您的布局的其余部分不会被切断,进度条上的wrap_content将确保它不会失真。
标签: android android-layout progress-bar