refactor(HeaderSubtitleLinearLayout.java): add back the firstFraction layout parameter
This commit is contained in:
@@ -1,31 +1,40 @@
|
||||
package org.joinmastodon.android.ui.views;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.TypedArray;
|
||||
import android.util.AttributeSet;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.joinmastodon.android.R;
|
||||
|
||||
/**
|
||||
* A LinearLayout for TextViews. First child TextView will get truncated if it doesn't fit, remaining will always wrap content.
|
||||
*/
|
||||
public class HeaderSubtitleLinearLayout extends LinearLayout{
|
||||
private float firstFraction;
|
||||
|
||||
public HeaderSubtitleLinearLayout(Context context){
|
||||
super(context);
|
||||
this(context, null);
|
||||
}
|
||||
|
||||
public HeaderSubtitleLinearLayout(Context context, AttributeSet attrs){
|
||||
super(context, attrs);
|
||||
this(context, attrs, 0);
|
||||
}
|
||||
|
||||
public HeaderSubtitleLinearLayout(Context context, AttributeSet attrs, int defStyleAttr){
|
||||
super(context, attrs, defStyleAttr);
|
||||
TypedArray ta=context.obtainStyledAttributes(attrs, R.styleable.HeaderSubtitleLinearLayout);
|
||||
firstFraction=ta.getFraction(R.styleable.HeaderSubtitleLinearLayout_firstFraction, 1, 1, 0.5f);
|
||||
ta.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec){
|
||||
if(getLayoutChildCount()>1){
|
||||
int remainingWidth=MeasureSpec.getSize(widthMeasureSpec);
|
||||
int fullWidth=MeasureSpec.getSize(widthMeasureSpec);
|
||||
int remainingWidth=fullWidth;
|
||||
for(int i=1;i<getChildCount();i++){
|
||||
View v=getChildAt(i);
|
||||
if(v.getVisibility()==GONE)
|
||||
@@ -36,7 +45,7 @@ public class HeaderSubtitleLinearLayout extends LinearLayout{
|
||||
}
|
||||
View first=getChildAt(0);
|
||||
if(first instanceof TextView){
|
||||
((TextView) first).setMaxWidth(remainingWidth);
|
||||
((TextView) first).setMaxWidth(Math.max(remainingWidth, (int)(firstFraction*fullWidth)));
|
||||
}
|
||||
}else{
|
||||
View first=getChildAt(0);
|
||||
@@ -55,4 +64,12 @@ public class HeaderSubtitleLinearLayout extends LinearLayout{
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setFirstFraction(float firstFraction){
|
||||
this.firstFraction=firstFraction;
|
||||
}
|
||||
|
||||
public float getFirstFraction(){
|
||||
return firstFraction;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user