如何设置imageButtons

时间:2015-07-30 21:47:17

标签: android android-layout android-imagebutton

我有几个imageButtons http://postimg.org/image/4zuj7kmib/的活动(对不起链接,但我有低lvl在这里发布图片)。

我想让它看起来像这个http://postimg.org/image/5tdkph53j/

这是我的tableLayout的一行:              

        <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent">

        <ImageButton
            android:id="@+id/countTariffBtn"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/plus"/>

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:layout_below="@+id/countTariffBtn"
                android:text="Doporuč tarif"/>
    </RelativeLayout>

        <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent">
        <ImageButton
            android:id="@+id/showTariffBtn"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="Tarify"
            android:src="@drawable/plus"
            android:layout_gravity="center"/>

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:layout_below="@+id/showTariffBtn"
                android:text="Seznam tarifů"/>
        </RelativeLayout>
        <RelativeLayout android:layout_width="fill_parent" android:layout_height="fill_parent">
        <ImageButton
            android:id="@+id/statisticsBtn"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:src="@drawable/plus"
            android:text="Statistiky"/>

            <TextView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:gravity="center"
                android:layout_below="@+id/statisticsBtn"
                android:text="Statistiky"/>
        </RelativeLayout>

    </TableRow>

1)为了删除imageButton的边框,我不能使用style =“?android:attr / borderlessButtonStyle”/&gt;因为我正在使用API​​ 9所以还有其他选择吗?

2)如何获得imageButton的大小以了解它的大小并将该图像调整为此大小?有没有办法如何从布局的图形设计中获得高度和宽度?

3)我如何保留这个边距让这些textViews像现在一样在同一个地方?

1 个答案:

答案 0 :(得分:0)

将背景设置为透明,添加填充,并将图像源(src属性)设置为您想要的可绘制项目。不要忘记将图像资源放在不同的密度目录(xhdpi,xxhdpi,hdpi,mdpi)中,以使它们在所有屏幕中都看起来很好。

相关问题