I'm trying to do this:
I've tried to make customized square button:
public class SquareButton extends Button {
public SquareButton(Context context, AttributeSet attrs) {
super(context, attrs);
// TODO Auto-generated constructor stub
}
public SquareButton(Context context) {
super(context);
}
@Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int height = getMeasuredHeight();
setMeasuredDimension(height, height);
}
}
and use it with icon and text under image, but without success. Button's background is a shape with gray stroke and white background color. Also there is an icon and string-text.
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#f5f5f5"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainMenuActivity" >
<TableLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" >
<TableRow
android:id="@+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<views.SquareButton
android:id="@+id/SquareButton01"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@drawable/main_menu_button"
android:drawableTop="@drawable/statistics_icon"
android:gravity="center_horizontal"
android:text="Button"
android:textAlignment="center" />
<views.SquareButton
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@drawable/main_menu_button"
android:drawableTop="@drawable/statistics_icon"
android:gravity="center_horizontal"
android:text="Button"
android:textAlignment="center" />
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<views.SquareButton
android:id="@+id/SquareButton03"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@drawable/main_menu_button"
android:drawableTop="@drawable/statistics_icon"
android:gravity="center_horizontal"
android:text="Button"
android:textAlignment="center" />
<views.SquareButton
android:id="@+id/SquareButton02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@drawable/main_menu_button"
android:drawableTop="@drawable/statistics_icon"
android:gravity="center_horizontal"
android:text="Button"
android:textAlignment="center" />
</TableRow>
<TableRow
android:id="@+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<views.SquareButton
android:id="@+id/SquareButton05"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@drawable/main_menu_button"
android:drawableTop="@drawable/statistics_icon"
android:gravity="center_horizontal"
android:text="Button"
android:textAlignment="center" />
<views.SquareButton
android:id="@+id/SquareButton04"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="2dp"
android:layout_weight="1"
android:background="@drawable/main_menu_button"
android:drawableTop="@drawable/statistics_icon"
android:gravity="center_horizontal"
android:text="Button"
android:textAlignment="center" />
</TableRow>
</TableLayout>
</LinearLayout>
Please, help. I've "googled" a lot of topics to find a solution of such problem, but not found yet. (((
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…