我無法將我的textview放置在RelativeLayout中間。我添加了這個參數在RelativeLayout中水平居中TextView不起作用
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
但它沒有幫助。
我的佈局
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/content_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="?android:attr/colorBackground"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context="ru.myseolife.a99torrentsalpha2.MainActivity"
android:gravity="center"
tools:showIn="@layout/app_bar_main"
>
<TextView
android:id="@+id/nothing_found"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:text="@string/nothingfound"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"/>
<LinearLayout
android:id="@+id/linlaHeaderProgress"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical"
android:visibility="gone"
>
<ProgressBar
android:id="@+id/progressBar"
style="@style/Widget.AppCompat.ProgressBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
</RelativeLayout>
有人知道是否可以? TextView垂直居中,但水平顯示在左側。
將android:gravity =「center」添加到您的textview。 –
@ AbdenaceurLichiheb謝謝,它幫助,但我認爲android:gravity =「center」適用於子元素。 –
在textview的情況下,它將應用於文本,它是否工作? –