使 TextView 自动适应视图中间

Make TextView auto fit in middle of views

我正在制作我的应用程序,但我无法实现它,我需要获得以下信息: Layout that I need

问题是我需要 6: 01.33 部分在左边,拼写(所有字母)在中间,按钮在右边。 我已经尝试了几种方法,例如使用 Weight,但我仍然无法实现。我也尝试使用 relativeLayout 但仍然没有。我把我做的代码给你:

<android.support.v7.widget.CardView
    app:cardBackgroundColor="?attr/cardBackgroundColor"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
   <LinearLayout
       android:weightSum="3"
       android:layout_width="match_parent"
       android:orientation="horizontal"
       android:layout_height="wrap_content">
       <TextView
           android:layout_weight="1"
           android:padding="10dp"
           android:layout_width="wrap_content"
           android:textColor="?attr/primaryTextColor"
           android:text="105: 46.23"
           android:layout_height="wrap_content" />
       <TextView
           android:layout_weight="1.5"
           android:padding="10dp"
           android:layout_width="wrap_content"
           android:textColor="?attr/secondaryTextColor"
           android:text="F2 R B L2 F R B L2 F R B2 L' R2 B F"
           android:layout_height="wrap_content" />
       <LinearLayout
           android:layout_weight="0.5"
           android:orientation="horizontal"
           android:layout_width="wrap_content"
           android:layout_height="wrap_content">

           <Button
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:background="@color/fui_transparent"
               android:text="+2"/>
           <Button
               android:layout_width="wrap_content"
               android:layout_height="wrap_content"
               android:background="@color/fui_transparent"
               android:text="DNF"/>
       </LinearLayout>
   </LinearLayout>
</android.support.v7.widget.CardView>

删除

android:weightSum="3"

和所有

android:layout_weight="xx"

并添加

android:layout_weight="1"

您的拼写 TextView 应该可以解决问题。你的第一个 TextView 应该在左边,按钮在右边。剩余的 space 将从您的 TextView 中提取。

使用相对布局

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
            <TextView
                android:padding="10dp"
                android:layout_alignParentLeft="true"
                android:id="@+id/leftView"
                android:layout_width="wrap_content"
                android:text="105: 46.23"
                android:layout_height="wrap_content" />
            <TextView
                android:id="@+id/midddleView"
                android:layout_toRightOf="@id/leftView"
                android:layout_toLeftOf="@id/rightView"
                android:padding="10dp"
                android:layout_width="match_parent"
                android:text="F2 R B L2 F R B L2 F R B2 L' R2 B F"
                android:layout_height="wrap_content" />
            <LinearLayout
                android:id="@+id/rightView"
                android:layout_alignParentRight="true"
                android:orientation="horizontal"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content">

                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="+2"/>
                <Button
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:text="DNF"/>
            </LinearLayout>
</RelativeLayout>