0

I am using autofittextview as textview tags (for better scaling). What I am trying is that text should always be aligned to center not matter what size. I have used gravity for this.

<LinearLayout
    android:id="@+id/orderFrequencyLayout"
    android:layout_width="0dp"
    android:layout_height="0dp"
    android:layout_marginBottom="8dp"
    android:layout_marginEnd="8dp"
    android:layout_marginLeft="8dp"
    android:layout_marginRight="8dp"
    android:layout_marginStart="8dp"
    android:layout_marginTop="8dp"
    android:orientation="vertical"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintLeft_toLeftOf="@+id/guideline14"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="parent">
    <LinearLayout
       android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_weight="0.3"
        android:orientation="horizontal">
        <me.grantland.widget.AutofitTextView
            android:id="@+id/orderFrequency"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:gravity="center_vertical|center_horizontal|center"
            android:maxLines="1"
            android:paddingBottom="5dp"
            android:text="0 seconds"
            android:textAlignment="center"
            android:textColor="@color/colorWarning"
            android:textSize="40sp"
            android:textStyle="bold"
            autofit:minTextSize="10sp" />
    </LinearLayout>

     <LinearLayout
        android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:layout_weight="6"
         android:orientation="horizontal">
         <me.grantland.widget.AutofitTextView
            android:layout_width="match_parent"
             android:layout_height="wrap_content"
             android:layout_gravity="bottom"
             android:gravity="top"
             android:maxLines="1"
             android:paddingBottom="5dp"
             android:text="Order Frequency"
             android:textAlignment="center"
             android:textSize="20sp"
             autofit:minTextSize="10sp" />
    </LinearLayout>
</LinearLayout>

And in design view it worked: Design View

But in my emultaor it gets displayed like this: Emulator

Any idea why? Thank you for your time!

Massimiliano Kraus
  • 3,638
  • 5
  • 27
  • 47
Alphonse
  • 661
  • 1
  • 12
  • 29

1 Answers1

0

remove android:layout_weight="0.3", the emulator display is maybe a different size than your designer

YingYang
  • 378
  • 1
  • 5
  • 15
  • 2
    found a solution... deleted android:layout_weight="6" and instead of android:layout_weight="0.3" I have set it to android:layout_weight="3"....but I don't quite understand layout weight .... should it be used for deciding how much of the available space you want something to fit...am I not supposed to give weight to both horizontal linearlayouts from inside the vertical one? – Alphonse Aug 23 '17 at 11:37
  • ah allright, i didnt see the android:layout_weight="6", only the 0.3, sry – YingYang Aug 23 '17 at 11:45
  • can you please try and explain to me something about this weight property...apparently I failed to understand it properly – Alphonse Aug 23 '17 at 11:46
  • have a look here: https://stackoverflow.com/questions/3995825/what-does-androidlayout-weight-mean – YingYang Aug 23 '17 at 11:48