【问题标题】:Textview has no width in RelativeLayout between 2 imagesTextview在2个图像之间的RelativeLayout中没有宽度
【发布时间】:2011-09-01 11:07:30
【问题描述】:

我有一个相对布局,其中包含图像、文本视图、图像的顺序。我打开了左对齐的左图像。右图打开了父对齐。并且打开了对齐中心父的文本视图。问题是,虽然所有内容在技术上都正确对齐,但 textview 虽然包含一个值,但已减少到布局中间的基本垂直线。为什么 textview 不根据其内容保持其宽度?谢谢

【问题讨论】:

    标签: android width textview android-relativelayout


    【解决方案1】:

    试试这个

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="fill_parent" android:layout_height="wrap_content">
        <RelativeLayout android:layout_height="match_parent"
            android:id="@+id/RelativeLayout01" android:layout_width="fill_parent">
            <ImageView android:layout_width="wrap_content" android:src="@drawable/icon"
                android:layout_height="wrap_content" android:id="@+id/ImageView01"
                android:layout_alignParentLeft="true"></ImageView>
            <TextView android:layout_width="wrap_content"
                android:layout_height="wrap_content" android:id="@+id/TextView01"
                android:layout_centerInParent="true" android:layout_centerVertical="true"
                android:text=" sdfsdf sdhfhskdhfkh hsdkfhksdhfh shdfkhsdkhfkjsdh fhskdfhksdhfjk sdfhsdkhfkjsdfhkhasdhfksa fsakhdfhsdfhkshdf skdhfkshdfk"
                android:layout_toRightOf="@+id/ImageView01" android:layout_toLeftOf="@+id/ImageView02"></TextView>
            <ImageView android:layout_width="wrap_content" android:src="@drawable/icon"
                android:layout_height="wrap_content" android:id="@+id/ImageView02"
                android:layout_alignParentRight="true"></ImageView>
        </RelativeLayout>
    </LinearLayout>
    

    【讨论】:

    • 这行得通,谢谢!然而,有点令人不安,因为中间文本视图中的文本一直移动到右侧图像而不是居中。但仅在设计者视图中。当它安装在我的手机上时,它是居中的。让我有点紧张……好像我无法完全控制它。
    • 这可能是设计师的问题,因为在我的设计师看来它没有与图像重叠。
    【解决方案2】:

    检查你的图像视图的宽度。将这 3 个东西的宽度设置为“包装内容”。

    【讨论】:

      猜你喜欢
      • 2013-08-18
      • 1970-01-01
      • 2013-11-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-10-11
      相关资源
      最近更新 更多