私は、LinearLayoutを拡張し、単純な3つの子(2 TextViewとImageView)を持つcustomViewを構築します。このビューをコードで動的に作成し、それを親LinearLayoutに追加します。このビューには背景があるので、画面上で簡単に見つけ出すことができます。その場所で正しく膨張されていますが、子供は表示されません。私は彼らが私のCustomView余りドットで示されているインスペクタでそれらを見つけるしようとすると、どういうわけか、(TextViewsとImageViewのに画像にテキスト値)私はLayoutInspectorをチェックし、それはすべてが正しくsettedされていることを示していますカスタムLinearLayout - 子が表示されない
私のCustomViewはDayTileViewと呼ばれ、これは灰色の背景の四角です。あなたが左の検査官で見ることができるように、子供たちは内容で満たされています。ビューのレイアウト:
<layout xmlns:android="http://schemas.android.com/apk/res/android">
<merge>
<TextView
android:id="@+id/day"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="@android:color/white"
/>
<TextView
android:id="@+id/dayName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:textColor="@android:color/white"
/>
<ImageView
android:id="@+id/padlock"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:src="@drawable/ic_padlock"
/>
</merge>
</layout>
そのコード:
public class DayTileView extends LinearLayout {
private DayTileBinding mBinding;
public DayTileView(Context context) {
super(context);
init();
}
public DayTileView(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init();
}
public DayTileView(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
private void init() {
mBinding = DataBindingUtil.inflate(LayoutInflater.from(getContext()), R.layout.day_tile, this, true);
setOrientation(VERTICAL);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
final int width = getDefaultSize(getSuggestedMinimumWidth(), widthMeasureSpec);
setMeasuredDimension(width, width);
}
public void setDay(int day, int month, int year) {
DateTime settedDay = new DateTime().withYear(year).withMonthOfYear(month).withDayOfMonth(day);
mBinding.day.setText(String.valueOf(day));
String dayName = settedDay.dayOfWeek().getAsText();
mBinding.dayName.setText(dayName);
boolean isWeekend = settedDay.dayOfWeek().get() == 6 || settedDay.dayOfWeek().get() == 7;
setBackgroundColor(ContextCompat.getColor(getContext(), isWeekend ? R.color.weekend_bg : R.color.weekday_bg));
}
}
そのまた別のCustomViewにおける使用のLinearLayoutしかしwiht水平方向(インスペクタにPlannedDayView):
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<merge>
<*.customViews.DayTileView
android:id="@+id/dayTile"
android:layout_width="0dp"
android:layout_weight="0.2"
android:layout_height="wrap_content"/>
<LinearLayout
android:id="@+id/container"
android:orientation="vertical"
android:layout_weight="1.2"
android:layout_width="0dp"
android:layout_height="wrap_content"/>
</merge>
</layout>
これを抱き締めることができるアイデアは誰でもありますか? LinearLayoutのマージを垂直方向と同じ背景に置き換えると、レイアウトのデザインモードのすべてが正しく表示されるため、動作するはずです。
EDIT: 私が知っていることは、View Initalization Padding Topを10pxに設定すると、ドットが下がっていることです。だから、いくつかの理由から、Androidが正しく膨張させられなかったようです。
と全景を測定しなければならない「のxmlnsを:アンドロイド=」のhttp://スキーマ.android.com/apk/res/android " xmlns:app =" http://schemas.android.com/apk/res-auto "この2つのプロパティを"
mmmatey
私はnamespace宣言をマージするために移動しましたが、助けになりません。レイアウトタグを削除することはできません。beacuseはバインドされません。すべてのcustomViewはこの方法で作成され、ワーキング。この1つだけが乱雑です。 – masztalski
DayTileViewで異なる重みを試してみると、元気はどうでしょうか。 – mmmatey