Reputation: 41
I would align a textview to the center of progressbar in Android.
Codes :
<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>
But it looks like :
How can I resolve this problem?
I need your help.
Upvotes: 0
Views: 340
Reputation: 1260
Please note that hardcoding width and height will give the same result on different devices, better to use match_parant or wrap_content. See below code let me know.
<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>
Upvotes: 0
Reputation: 4910
Try to use Relative Layout.
<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>
Upvotes: 2