うまくいけば、この質問は私が間違った期待を持っていることで解決しますが、私は Android Studio 0.2.10 を使用しており、RelativeLayout を実際の RelativeLayout として拡張するカスタム ビュー グループの XML を認識するレンダリング システムに問題があります。これの影響は、カスタムビューの子が、利用できるはずのオプションを取得していないことです...たとえば、layout_width、layout_height、またはalignComponent(これは、カスタムレイアウトをレイアウトとしてまったく認識していないことを示しているようです) )。
もちろん、これらの属性を手動で XML に追加するか、一時的にルート タグを RelativeLayout に設定するだけで、デザイン ツールは正常に動作するようですが、AndroidStudio がカスタム拡張機能を適切に解決できないため、設計上何か間違ったことをしています。私は Android 開発に不慣れなので、これを IDE のバグとして時期尚早に片付けたくありませんでした。
public class CommentCellView extends RelativeLayout {
private static String TAG = "CommentCellView";
final private CommentCellView _cellView;
private Comment _comment;
public CommentCellView(Context context) {
super(context);
_cellView = this;
}
public CommentCellView(Context context, AttributeSet attrs) {
super(context, attrs);
_cellView = this;
}
public CommentCellView(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
_cellView = this;
}
public void setComment(Comment comment) {
_comment = comment;
TextView nameTextView = (TextView)this.findViewById(R.id.commentcell_nameTextView);
TextView commentTextView = (TextView)this.findViewById(R.id.commentcell_commentTextView);
TextView dateTextView = (TextView)this.findViewById(R.id.commentcell_dateTextView);
nameTextView.setText(comment.name);
commentTextView.setText(comment.comment);
dateTextView.setText(comment.date);
}
}
<com.testapp.CommentCellView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="80dp"
android:background="#ffffff">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/commentcell_backgroundImageView"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:src="@drawable/comment_bg"/>
<ImageView
android:layout_width="50dp"
android:layout_height="50dp"
android:id="@+id/commentcell_avatarImageView"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:src="@drawable/avatar"
android:layout_marginLeft="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/commentcell_nameTextView"
android:layout_alignTop="@+id/commentcell_avatarImageView"
android:layout_toRightOf="@+id/commentcell_avatarImageView"
android:layout_marginLeft="10dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Medium Text"
android:id="@+id/commentcell_commentTextView"
android:layout_below="@+id/commentcell_nameTextView"
android:layout_alignLeft="@+id/commentcell_nameTextView"
android:textColor="#999999"
android:layout_marginTop="2dp"
android:layout_alignParentRight="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="@+id/commentcell_dateTextView"
android:layout_alignBottom="@+id/commentcell_avatarImageView"
android:layout_toRightOf="@+id/commentcell_avatarImageView"
android:layout_marginLeft="10dp"/>
</com.testapp.CommentCellView>