2016-10-23 3 views
-2

Так что у меня есть проблема с центрированием текста внутри TextView. Я хочу, чтобы текст был помещен в центр моего Textview. Вот е мой код:Центрирование текста в Textview

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:background="#EAEAEA" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_centerVertical="true" 
    android:layout_centerHorizontal="true" 
    android:weightSum="3"> 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"> 
    <ImageView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:id="@+id/Ciech" 
     android:src="@drawable/ciech" 
     android:layout_marginTop="16dp" 
     android:layout_marginLeft="16dp" 
     android:layout_marginRight="16dp"/> 
</LinearLayout> 


<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1" 
    android:background="@drawable/border" 
    android:layout_margin="5dp"> 
    <ScrollView 
     android:layout_width="match_parent" 
     android:layout_height="match_parent"> 
     <TextView 

      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:text="sampletext" 
      android:layout_margin="16dp"/> 
    </ScrollView> 
</LinearLayout> 


    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="0dp" 
    android:layout_weight="1"> 
     <ScrollView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent"> 
     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:padding="16dp"> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/globus" 
       android:src="@drawable/grid_world" 
       /> 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="sampletext" 
       android:textColor="#000000" 
       android:textStyle="bold" 
       android:layout_alignBottom="@+id/globus" 
       android:layout_toEndOf="@+id/globus" 
       android:layout_alignParentTop="true" 
       android:layout_toRightOf="@+id/globus" 
       android:gravity="center" /> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/koperta" 
       android:src="@drawable/close_envelope" 
       android:layout_below="@+id/globus"/> 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="sampletext" 
       android:textColor="#000000" 
       android:textStyle="bold" 
       android:layout_alignBottom="@+id/koperta" 
       android:layout_alignTop="@+id/koperta" 
       android:layout_toRightOf="@+id/koperta" 
       android:gravity="center" /> 
      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/torba" 
       android:src="@drawable/portfolio_black_tool" 
       android:layout_below="@+id/koperta"/> 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="sampletext" 
       android:textColor="#000000" 
       android:textStyle="bold" 
       android:layout_alignBottom="@+id/torba" 
       android:layout_toEndOf="@+id/torba" 
       android:layout_alignTop="@+id/torba" 
       android:layout_toRightOf="@+id/torba" 
       android:gravity="center" /> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/znaczek" 
       android:src="@drawable/map_marker" 
       android:layout_below="@+id/torba"/> 
      <TextView 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:text="sampletext" 
       android:textColor="#000000" 
       android:textStyle="bold" 
       android:layout_alignBottom="@+id/znaczek" 
       android:layout_toEndOf="@+id/znaczek" 
       android:layout_alignTop="@+id/znaczek" 
       android:layout_toRightOf="@+id/znaczek" 
       android:gravity="center" /> 

     </RelativeLayout> 
     </ScrollView> 
    </LinearLayout> 

</LinearLayout> 

Когда я смотрю на предварительный просмотр в Android Studio он показывает мне: this И это именно то, что я хочу. Тем не менее, когда я запускаю эмулятор, то вдруг меняется и выглядит следующим образом: this

Может кто-то помочь мне с этим, я сбит с толку

+0

Можете ли вы разместить полный xml? –

+0

Добавить свойство text: 'android: layout_gravity =" center_vertical "' – pRaNaY

+0

android: layout_gravity = "center_vertical" ничего не меняет. Я отправил свой полный xml –

ответ

Смежные вопросы