在Android中将文本视图与progressbar的中心对齐
我会在Android中将文本视图与progressbar的中心对齐 代码:在Android中将文本视图与progressbar的中心对齐,android,Android,我会在Android中将文本视图与progressbar的中心对齐 代码: <LinearLayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/oyunhamletv" android:layout_marginTop="25dp"
<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>
尝试使用相对布局
<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\u parant或wrap\u 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>
请注意,硬编码的宽度和高度在不同的设备上会给出相同的结果,最好使用match\u parant或wrap\u 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>
你的意思是当进度更新时,textview位置也会根据进度更新到中心???@Niceumang No。我会将textview的位置更新到进度条的中心。你的意思是当进度更新时,textview的位置也会根据进度更新到中心???@Niceumang No.我会将textview的位置更新到进度条的中心。@HasanGüleç我很高兴它有帮助@HasanGüleç我很高兴这有帮助!