Skip to content

Commit

Permalink
fix filtertab issue
Browse files Browse the repository at this point in the history
  • Loading branch information
Jamling committed Apr 17, 2017
1 parent cd29244 commit 347d4c8
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 1 deletion.
2 changes: 1 addition & 1 deletion library/src/cn/ieclipse/af/view/FilterTabView.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public FilterTabView(FilterTabHost expandableLayout) {
}

public FilterTabView(FilterTabHost expandableLayout, CharSequence title) {
this(expandableLayout, null, null);
this(expandableLayout, title, null);
}

public FilterTabView(FilterTabHost expandableLayout, CharSequence title, OnPopupItemClickListener listener) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* Copyright (C) 2015-2016 adviser2
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package cn.ieclipse.af.demo.common.view;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.os.Build;
import android.support.annotation.RequiresApi;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.widget.ToggleButton;

/**
* Description
*
* @author Jamling
*/
public class SimpleFilterTab extends ToggleButton {
@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)
public SimpleFilterTab(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
}

public SimpleFilterTab(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
}

public SimpleFilterTab(Context context, AttributeSet attrs) {
super(context, attrs);
}

public SimpleFilterTab(Context context) {
super(context);
}

@Override
protected void onDraw(Canvas canvas) {
Drawable[] drawables = getCompoundDrawables();
if (drawables != null) {
Drawable drawableLeft = drawables[2]; // right drawable
if (drawableLeft != null) {
CharSequence text = getText();
if (TextUtils.isEmpty(text)) {
text = getHint();
}
float textWidth = 0;
if (!TextUtils.isEmpty(text)) {
textWidth = getPaint().measureText(text.toString());
}
int drawablePadding = getCompoundDrawablePadding();
int drawableWidth = 0;
drawableWidth = drawableLeft.getIntrinsicWidth();
float bodyWidth = textWidth + drawableWidth + drawablePadding;
float middle = (getMeasuredWidth() - bodyWidth) / 2;
if (middle > 0) {
canvas.translate(-middle, 0);
}
}
}
super.onDraw(canvas);
}
}
20 changes: 20 additions & 0 deletions sample/src/main/res/layout/common_filter_tab_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?xml version="1.0" encoding="utf-8"?>
<cn.ieclipse.af.demo.common.view.SimpleFilterTab
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_weight="1"
android:background="@null"
android:drawablePadding="3dp"
android:drawableRight="@android:drawable/arrow_down_float"
android:gravity="right|center_vertical"
android:maxLines="1"
android:textColor="@color/fg_main_bottom_selector"
android:textOff="@null"
android:textOn="@null"
android:textSize="16sp"
android:textStyle="bold"
tools:text="Item1">

</cn.ieclipse.af.demo.common.view.SimpleFilterTab>

0 comments on commit 347d4c8

Please sign in to comment.