我有一个<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/fragment_profile"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/svprofile"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<LinearLayout
android:id="@+id/linLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:orientation="vertical">
<de.hdodenhof.circleimageview.CircleImageView
android:id="@+id/imageToUpload"
android:layout_width="200dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:src="@drawable/ic_menu_camera"
android:layout_marginTop="10dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Profile Detail"
android:id="@+id/tvProfileDetail"
android:layout_marginTop="30dp" />
<EditText
android:id="@+id/etFullname"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/Fullname"
android:editable="false"/>
<EditText
android:id="@+id/etEmail"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="@string/Email"/>
<EditText
android:id="@+id/etPhone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="phone"
android:hint="@string/Phone"/>
<EditText
android:id="@+id/etAddress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minLines="1"
android:maxLines="3"
android:hint="@string/Address"/>
<EditText
android:id="@+id/etDirectSuperiorName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="@string/DirectSuperiorName"
android:editable="false"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Leave Balance"
android:id="@+id/tvSisaCuti"
android:layout_marginTop="20dp" />
<EditText
android:id="@+id/etSisaCuti"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="Sisa Cuti"
android:layout_marginTop="1dp"
android:editable="false"
android:paddingTop="10dp" />
<ListView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/lvProfile"
android:choiceMode="singleChoice"
android:headerDividersEnabled="false"
android:divider="@null"
android:dividerHeight="0dp"/>
</LinearLayout>
</ScrollView>
包含一些customView
,如下所示:
我已将subViews
尾随约束设置为它的superView = 4
我希望我的messageLabel
宽度约束将基于customView
自动设置。如果我像这样创建customView:
messageLabel
如何设置它的宽度大小,因为messageLabel可以很长或排序。
答案 0 :(得分:0)
我将customView
宽度大小设置在它的子标签上,如下所示
customView.frame.size.width = customView.messageLabelWidth + 50 // 50 here is for imageView width and some spacing.
messageLabelWidth
FlyingMessageDisplayView
var messageLabelWidth: CGFloat {
get {
return messageLabel.intrinsicContentSize.width
}
}
它将根据文本长度计算标签的宽度,然后更新customView