代码之家  ›  专栏  ›  技术社区  ›  DevWithZachary

Android布局中扭曲的ProgressBar微调器

  •  4
  • DevWithZachary  · 技术社区  · 12 年前

    我有一个进度微调器,布局如下:

    <ProgressBar
            android:id="@+id/progressBar1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:paddingBottom="10dp"
            android:paddingTop="10dp" >
    
    </ProgressBar>
    

    它应该看起来像:

    enter image description here

    然而,在一些生姜面包设备上,它看起来像:

    enter image description here

    我不明白为什么在旧设备上看起来好像坏了?

    编辑 完整布局:

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
    
        <WebView
            android:id="@+id/webView1"
            android:layout_width="fill_parent"
            android:layout_height="434dp"
            android:layout_weight="0.45" />
    
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="50dp"
            android:layout_gravity="center"
            android:background="@color/background" >
    
            <ImageView
                android:id="@+id/left"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="0.10"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:src="@drawable/ic_arrowleft" />
    
            <ImageView
                android:id="@+id/right"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_weight="0.10"
                android:paddingBottom="10dp"
                android:paddingTop="10dp"
                android:src="@drawable/ic_arrowright" />
    
            <ProgressBar
                android:id="@+id/progressBar1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginBottom="10dp"
                android:layout_marginTop="10dp" >
    
            </ProgressBar>
    
            <TextView
                android:id="@+id/grabit"
                android:layout_width="0dp"
                android:layout_height="46dp"
                            android:layout_weight="0.50"
    
                android:layout_gravity="center"
                android:background="@color/selected"
                android:gravity="center"
                android:text="GRAB IT"
                android:textColor="#fff"
                android:textStyle="bold" />
    
        </LinearLayout>
    
    </LinearLayout>
    
    1 回复  |  直到 12 年前
        1
  •  3
  •   Ryan S    12 年前

    不要使用填充,而是使用边距。就像这样:

    <ProgressBar
            android:id="@+id/progressBar1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_marginBottom="10dp"
            android:layout_marginTop="10dp" >
    
    </ProgressBar>
    

    编辑: 问题是在水平线性布局中:

    android:layout_height="50dp"
    

    姜饼中的进度条更大,这意味着你迫使它挤压自己,从而导致翘曲。而是使用wrap_content。