fix some layout issue caused by textview

This commit is contained in:
侯歌 2022-01-26 11:15:58 +08:00
parent 5ee4a2598d
commit 291d4abc29
7 changed files with 27 additions and 19 deletions

View File

@ -83,7 +83,7 @@ class IDGenerater(object):
for top, dirs, nondirs in os.walk(scanPath):
for item in nondirs:
fname=os.path.join(top, item)
if item.find('.xml')<0 or self.dirHasId(fname)<0:
if (not item.endswith('.xml')) or (self.dirHasId(fname)<0):
continue
newestdate=os.stat(fname);
if(lastmodifytime<newestdate.st_mtime):

View File

@ -20,20 +20,20 @@ FrameLayout::FrameLayout(Context* context,const AttributeSet& attrs)
mForegroundPaddingLeft=mForegroundPaddingRight=0;
mForegroundPaddingTop =mForegroundPaddingBottom=0;
}
//@android.view.RemotableViewMethod
void FrameLayout::setForegroundGravity(int foregroundGravity){
#if 0
if (getForegroundGravity() != foregroundGravity) {
ViewGroup::setForegroundGravity(foregroundGravity);
// calling get* again here because the set above may apply default constraints
Drawable* foreground = getForeground();
if (getForegroundGravity() == Gravity.FILL && foreground != null) {
if (getForegroundGravity() == Gravity::FILL && foreground ) {
Rect padding;
if (foreground.getPadding(padding)) {
mForegroundPaddingLeft = padding.x;
mForegroundPaddingTop = padding.y;
mForegroundPaddingRight = padding.right();
mForegroundPaddingBottom = padding.bottom();
if (foreground->getPadding(padding)) {
mForegroundPaddingLeft = padding.left;
mForegroundPaddingTop = padding.top;
mForegroundPaddingRight = padding.width;
mForegroundPaddingBottom = padding.height;
}
} else {
mForegroundPaddingLeft = 0;
@ -43,7 +43,6 @@ void FrameLayout::setForegroundGravity(int foregroundGravity){
}
requestLayout();
}
#endif
}
LayoutParams* FrameLayout::generateDefaultLayoutParams()const {
@ -59,7 +58,7 @@ bool FrameLayout::checkLayoutParams(const LayoutParams* p)const{
}
LayoutParams* FrameLayout::generateLayoutParams(const LayoutParams* lp)const {
if (true/*sPreserveMarginParamsInLayoutParamConversion*/) {
if (false/*sPreserveMarginParamsInLayoutParamConversion*/) {
if (dynamic_cast<const FrameLayoutParams*>(lp)) {
return new LayoutParams(*(FrameLayoutParams*) lp);
} else if (dynamic_cast<const MarginLayoutParams*>(lp)) {

View File

@ -48,7 +48,7 @@ const std::string LayoutParams::sizeToString(int size) {
MarginLayoutParams::MarginLayoutParams(Context*c,const AttributeSet& attrs)
:LayoutParams(c,attrs){
int margin=attrs.getDimensionPixelSize("layout_margin",-1);
if(margin>0){
if(margin>=0){
leftMargin=topMargin=rightMargin=bottomMargin=margin;
}else{
int horzMargin = attrs.getDimensionPixelSize("layout_marginHorizontal",-1);

View File

@ -32,10 +32,14 @@ LinearLayout::LayoutParams::LayoutParams(int width, int height, float weight)
LinearLayout::LayoutParams::LayoutParams(const ViewGroup::LayoutParams& p)
:ViewGroup::MarginLayoutParams(p){
this->weight = .0f;
gravity=Gravity::NO_GRAVITY;
}
LinearLayout::LayoutParams::LayoutParams(const ViewGroup::MarginLayoutParams&source)
:ViewGroup::MarginLayoutParams(source){
this->weight = .0f;
gravity=Gravity::NO_GRAVITY;
}
LinearLayout::LayoutParams::LayoutParams(const LinearLayout::LayoutParams&source)
@ -545,7 +549,7 @@ void LinearLayout::measureHorizontal(int widthMeasureSpec, int heightMeasureSpec
totalWeight += lp->weight;
bool useExcessSpace = lp->width == 0 && lp->weight > 0;
const bool useExcessSpace = lp->width == 0 && lp->weight > 0;
if (widthMode == MeasureSpec::EXACTLY && useExcessSpace) {
// Optimization: don't bother measuring children who are only
// laid out using excess space. These views will get measured

View File

@ -148,9 +148,9 @@ void TabLayout::addTabFromItemView(TabItem* item){
tab->setIcon(item->mIcon);
}
//tab->setCustomView(item->mCustomLayout);
tab->setCustomView(item->mCustomLayout);
//tab->setContentDescription(item->getContentDescription());//getContentDescription inherited from View.
tab->setContentDescription(item->getContentDescription());//getContentDescription inherited from View.
addTab(tab);
}
@ -755,7 +755,7 @@ int TabLayout::getTabMinWidth() {
return mMode == MODE_SCROLLABLE ? mScrollableTabMinWidth : 0;
}
LayoutParams* TabLayout::generateLayoutParams(const AttributeSet& attrs){
ViewGroup::LayoutParams* TabLayout::generateLayoutParams(const AttributeSet& attrs)const{
return generateDefaultLayoutParams();
}
@ -806,6 +806,11 @@ TabLayout::Tab& TabLayout::Tab::setCustomView(View*v){
return *this;
}
TabLayout::Tab& TabLayout::Tab::setCustomView(const std::string&resid){
View*v=LayoutInflater::from(mParent->getContext())->inflate(resid,nullptr,false);
return setCustomView(v);
}
Drawable* TabLayout::Tab::getIcon()const{
return mIcon;
}

View File

@ -36,6 +36,7 @@ public:
void setTag(void*tag);
View* getCustomView()const;
Tab& setCustomView(View*);
Tab& setCustomView(const std::string&);
Drawable* getIcon()const;
Tab& setIcon(Drawable* icon);
int getPosition()const;
@ -277,7 +278,7 @@ public:
View& addView(View* child, ViewGroup::LayoutParams* params)override;
View& addView(View* child, int index, ViewGroup::LayoutParams* params)override;
LayoutParams* generateLayoutParams(const AttributeSet& attrs);
ViewGroup::LayoutParams* generateLayoutParams(const AttributeSet& attrs)const override;
};
}//endof namespace

View File

@ -249,8 +249,7 @@ TextView::TextView(Context*ctx,const AttributeSet& attrs)
mTextColor =ctx->getColorStateList(attrs.getString("textColor"));
mLayout=new Layout(20,50);
mHintLayout=new Layout(20,50);
std::string txt=attrs.getString("text");
mLayout->setText(txt);
setText(attrs.getString("text"));
Drawable* left =ctx->getDrawable(attrs,"drawableLeft");
Drawable*right =ctx->getDrawable(attrs,"drawableRight");
@ -261,7 +260,7 @@ TextView::TextView(Context*ctx,const AttributeSet& attrs)
setCompoundDrawablePadding(attrs.getDimensionPixelSize("drawablePadding",0));
setMinHeight(attrs.getDimensionPixelSize("minHeight", -1));
setMaxHeight(attrs.getDimensionPixelSize("maxHeight", -1));
setMaxHeight(attrs.getDimensionPixelSize("maxHeight", mMaximum));
setMinWidth(attrs.getDimensionPixelSize("minWidth", INT_MIN));
setMaxWidth(attrs.getDimensionPixelSize("maxWidth", INT_MAX));