簡體   English   中英

將文本視圖與 Android 中進度條的中心對齊

[英]Align a textview to the center of progressbar in Android

我會將 textview 與 Android 中進度條的中心對齊。

代碼:

<LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_below="@+id/oyunhamletv"
            android:layout_marginTop="25dp"
            android:gravity="center_horizontal"
            android:orientation="vertical"
    >

    <ProgressBar
            android:id="@+id/hamlebar"
            android:layout_width="160dp"
            android:layout_height="35dp"
            android:maxHeight="35dp"
            android:minHeight="30dp"
            android:scaleY="8"
            style="@style/Widget.AppCompat.ProgressBar.Horizontal"
            android:max="100"
    />

    <TextView
            android:id="@+id/bartext"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Hamle"
            android:layout_gravity="center"
            android:background="@android:color/transparent"

    />

    </LinearLayout>

但它看起來像:

照片進度條和文本視圖

我該如何解決這個問題?

我需要你的幫助。

嘗試使用相對布局。

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

    <ProgressBar
        android:id="@+id/hamlebar"
        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
        android:layout_width="160dp"
        android:layout_height="35dp"
        android:layout_centerInParent="true"
        android:max="100"
        android:maxHeight="35dp"
        android:minHeight="30dp"
        android:scaleY="8" />

    <TextView
        android:id="@+id/bartext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:layout_gravity="center"
        android:background="@android:color/transparent"
        android:text="Hamle" />


</RelativeLayout>

請注意,硬編碼寬度和高度將在不同設備上給出相同的結果,最好使用match_parantwrap_content 請參閱下面的代碼讓我知道。

<LinearLayout android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="25dp"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android">

    <ProgressBar
        android:id="@+id/hamlebar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        style="@style/Widget.AppCompat.ProgressBar.Horizontal"
        android:max="100" />

    <TextView
        android:id="@+id/bartext"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hamle"
        android:layout_marginTop="10dp"
        android:layout_gravity="center"
        android:background="@android:color/transparent" />

</LinearLayout>

暫無
暫無

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

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