Xia*_*Han 8 android button imagebutton
我想在图像按钮下添加文本,这些文本也是可点击的,并且将被重定向到与图像按钮相同的活动.基本上它就像任何Android手机中的应用程序列表,例如
Ree*_*eed 12
如果你ImageButton在XML中声明了你的声明,那么只需将它放入一个LinearLayout包含a TextView并在其中设置onClickListener的LinearLayout.结构就像
<LinearLayout
... > <!-- This is the LinearLayout for the xml document -->
<!-- Some other layout code here if you please -->
<LinearLayout
android:id="@+id/linLayout"
... >
<ImageButton
... />
<TextView
... />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
然后在你的java中:
LinearLayout layout = (LinearLayout)findViewById(R.id.linLayout);
layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});
Run Code Online (Sandbox Code Playgroud)
如果你ImageButton通过java代码动态添加每个代码,那么它仍将保持相同的结构.如果我需要添加任何内容,请告诉我.
setAlpha并执行以下操作
<Button
android:id="@+id/comparePack"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="5dp"
android:onClick="compareButtonClick"
android:text="@string/compare"
android:drawableTop="@drawable/compare1edit"
android:gravity="left|center_vertical"/>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
20457 次 |
| 最近记录: |