我完全迷失了这个 LayoutInflater。我正在尝试将代码中的项目与位于远程布局中的项目链接起来。我尝试了三种不同版本的充气机。它们都不起作用。然而,这个版本似乎是使用最广泛的。这是充气机乱码的片段:
setContentView(R.layout.browse);
LayoutInflater li = (LayoutInflater) this.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final ImageButton editBrowseButton = (ImageButton) li.inflate(R.layout.row, null).findViewById(R.id.imageButton1);
editBrowseButton.setAlpha(50);
这感觉有点像我错过了什么。我需要退货吗?.setAlpha 没有任何意义。我只是把它放进去测试一下。显然,它不会改变透明度。如果我添加一个 onClickListner,它就不起作用。但是,我没有例外。活动开始正常。下面是 row.xml 的相关 XML 代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linearLayout1"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:focusable="true"
>
<TableRow
android:id="@+id/tableRow1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:focusable="true"
>
<TextView
android:id= "@+id/txtItem"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text = "Item"
android:focusable="true"
/>
</TableRow>
<TableRow
android:id="@+id/tableRow2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:focusable="false"
>
<ImageButton
android:src="@drawable/editbtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/imageButton1"
></ImageButton>
</TableRow>
</LinearLayout>
EDIT_01
新方法尝试过但失败了。结果相同。什么都没发生。
setContentView(R.layout.browse);
LayoutInflater li = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ViewGroup rowView = (ViewGroup) li.inflate(R.layout.row, null);
LinearLayout rowLinLay = (LinearLayout) rowView
.findViewById(R.id.linearLayout1);
TableRow rowTableRow = (TableRow)rowLinLay.findViewById(R.id.tableRow2);
ImageButton editBrowseButton = (ImageButton) rowTableRow
.findViewById(R.id.imageButton1);
EDIT_02
setContentView(R.layout.browse);
ExpandableListView browseView = (ExpandableListView) findViewById(android.R.id.list);
LayoutInflater li = (LayoutInflater) this
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = (View) li.inflate(R.layout.row, null);
TableRow rowTable = (TableRow) rowView.findViewById(R.id.tableRow2);
ImageButton editBrowseButton = (ImageButton) rowTable
.findViewById(R.id.imageButton1);
editBrowseButton.setAlpha(100);