简体   繁体   English

使用layout_weight更改textview大小

[英]Using layout_weight changes the textview size

I have two TextViews which I want to be centered (in the middle) and they should have a fix Size of about 30 dp, how can I achieve that? 我有两个要居中的TextView(在中间),并且它们的固定大小约为30 dp,如何实现?

<LinearLayout

    android:layout_width="match_parent"
    android:layout_height="wrap_content"

    android:orientation="horizontal">
<TextView

    android:layout_weight="0.5"
    android:padding="7dp"
    android:textSize="30sp"
    android:layout_marginRight="20dp"
    android:layout_width="30dp"
    android:layout_height="wrap_content"
    android:text="N"
    android:background="@color/black"
    android:textColor="@color/white"
    android:id="@+id/textView1"  android:gravity="center" />
    <TextView

        android:layout_weight="0.5"
        android:padding="7dp"
        android:textSize="30sp"
        android:layout_marginRight="20dp"
        android:layout_width="30dp"
        android:layout_height="wrap_content"

        android:text="N"
        android:background="@color/black"
        android:textColor="@color/white"
        android:id="@+id/textView2"  android:gravity="center"/>

If I understand you correctly you want to use 如果我理解正确,您想使用

android:gravity="center"

in your LinearLayout 在您的LinearLayout中

Something similar to this: 类似于以下内容:

    <LinearLayout

    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:gravity="center">

    <TextView
        android:padding="7dp"
        android:textSize="30sp"
        android:layout_width="30dp"
        android:layout_height="wrap_content"
        android:text="N"
        android:background="@color/black"
        android:textColor="@color/white"
        android:id="@+id/textView1"  android:gravity="center"
        android:layout_marginRight="10dp" />

    <TextView
        android:padding="7dp"
        android:textSize="30sp"
        android:layout_width="30dp"
        android:layout_height="wrap_content"

        android:text="N"
        android:background="@color/black"
        android:textColor="@color/white"
        android:id="@+id/textView2"  android:gravity="center"
        android:layout_marginLeft="10dp" />

Try this!!!! 尝试这个!!!!

<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal">
<TextView
android:layout_weight="0.5"
android:padding="7dp"
android:textSize="30sp"
android:layout_marginRight="20dp"
android:layout_width="30dp"
android:layout_height="wrap_content"
android:text="N"
android:background="@color/black"
android:textColor="@color/white"
android:id="@+id/textView1" />
<TextView
    android:layout_weight="0.5"
    android:padding="7dp"
    android:textSize="30sp"
    android:layout_marginRight="20dp"
    android:layout_width="30dp"
    android:layout_height="wrap_content"
    android:text="N"
    android:background="@color/black"
    android:textColor="@color/white"
    android:id="@+id/textView2" />

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM