Với GridLayout đây là định nghĩa bố cục hợp lệ. Không có cảnh báo về 'layout_height' attribute should be defined
hoặc 'layout_width' attribute should be defined
Mở rộng GridLayout
<GridLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView />
</GridLayout>
Trên otherhand, nếu tôi mở rộng GridLayout cách bố trí tương đương cho cả hai cảnh báo 'layout_height' attribute should be defined
và 'layout_width' attribute should be defined
<ExtendedGridLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView />
</ExtendedGridLayout>
này là những gì các GridLayout mở rộng trông giống như
package com.github.extendedgridlayout;
import android.annotation.TargetApi;
import android.content.Context;
import android.os.Build;
import android.util.AttributeSet;
import android.widget.GridLayout;
@SuppressWarnings("unused")
public class ExtendedGridLayout extends GridLayout {
public ExtendedGridLayout(Context context){
super(context);
}
public ExtendedGridLayout(Context context, AttributeSet attrs) {
super(context, attrs);
}
public ExtendedGridLayout(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public ExtendedGridLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}
}
Tôi đã thử xem qua GridLayout
nguồn, và nó có vẻ như những gì họ đã làm là để mở rộng ViewGroup.LayoutParams và thiết lập một chiều rộng mặc định và chiều cao, giống như cho PercentRelativeLayout
Vì vậy, nó có vẻ như dựa trên thừa kế, ExtendedGridLayout cũng nên đặt chiều rộng mặc định và chiều cao cho con của nó hoặc làm bất cứ điều gì GridLayout làm để tránh thông báo cảnh báo trong trình soạn thảo bố cục.
Vì vậy, câu hỏi của tôi là tại sao ExtendedGridLayout
có cảnh báo và làm cách nào để ngăn chặn nó?
Cá nhân tôi thích tạo chế độ xem của riêng mình bằng 'LinearLayout' thay vì sử dụng 'GridLayout' vô ích. –
@uval gridview đặt chiều rộng và chiều cao của con của nó. Đặc biệt khi bạn nói rõ colum và số hàng – Olumide