wow!! configurable first fraction
This commit is contained in:
parent
2e4f04cd88
commit
5135653cd3
|
@ -1,27 +1,34 @@
|
|||
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 me.grishka.appkit.utils.V;
|
||||
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);
|
||||
System.out.println("FRACTION " + firstFraction);
|
||||
ta.recycle();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -39,7 +46,7 @@ public class HeaderSubtitleLinearLayout extends LinearLayout{
|
|||
}
|
||||
View first=getChildAt(0);
|
||||
if(first instanceof TextView){
|
||||
((TextView) first).setMaxWidth(Math.max(remainingWidth, fullWidth/3*2));
|
||||
((TextView) first).setMaxWidth(Math.max(remainingWidth, (int)(firstFraction*fullWidth)));
|
||||
}
|
||||
}else{
|
||||
View first=getChildAt(0);
|
||||
|
@ -58,4 +65,12 @@ public class HeaderSubtitleLinearLayout extends LinearLayout{
|
|||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
public void setFirstFraction(float firstFraction){
|
||||
this.firstFraction=firstFraction;
|
||||
}
|
||||
|
||||
public float getFirstFraction(){
|
||||
return firstFraction;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingHorizontal="16dp">
|
||||
|
@ -107,6 +108,7 @@
|
|||
|
||||
<org.joinmastodon.android.ui.views.HeaderSubtitleLinearLayout
|
||||
android:id="@+id/name_wrap"
|
||||
app:firstFraction="60%"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_toEndOf="@id/avatar"
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<org.joinmastodon.android.ui.views.HeaderSubtitleLinearLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
app:firstFraction="30%"
|
||||
android:orientation="horizontal"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
|
|
|
@ -114,4 +114,8 @@
|
|||
<declare-styleable name="NestedRecyclerScrollView">
|
||||
<attr name="takePriorityOverChildViews" format="boolean"/>
|
||||
</declare-styleable>
|
||||
|
||||
<declare-styleable name="HeaderSubtitleLinearLayout">
|
||||
<attr name="firstFraction" format="fraction"/>
|
||||
</declare-styleable>
|
||||
</resources>
|
Loading…
Reference in New Issue