我正在开发一个化学应用程序。但我有一个问题是创建一个适合设备显示大小的周期表。但是我无法做到。我尝试了按钮。但它超出了空间限制,我想要在不使用滚动视图的情况下这样做。最后我选择带有文本视图的图像按钮。是否可能或者有一种简单的方法。请帮助
答案 0 :(得分:1)
尝试使用TextView布局的ImageButton,如:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageButton
android:id="@+id/img_button"
android:layout_width="match_parent"
android:layout_height="@dimen/img_button_height"
android:layout_alignParentTop="true"
android:adjustViewBounds="false"
android:cropToPadding="false"
android:src="@drawable/your_image"
android:background="@android:color/transparent"/>
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
//android:layout_alignTop="@+id/img_button"
//android:layout_alignLeft="@+id/img_button"
//position your TextView inside ImageButton
//android:layout_marginLeft="20dp"
//android:layout_marginTop="5dp"
android:textSize="13sp"
android:textColor="@color/white"
android:typeface="sans"
android:text="" />
</RelativeLayout>
答案 1 :(得分:0)
使用imageView而不是imageButton并将layout_width和layout_height设置为match_parent并将src设置为周期表的图像(确保使用src而不是背景图像,因为这将正确缩放它)。如果您需要为其添加点击次数,则可以采用与imageButton相同的方式进行编程。