这里我将布局扩展到另一个具有列表视图的布局
public class MyListAdapter extends ArrayAdapter<Certs>{
Context context;
public MyListAdapter(Context context, int resourceId,List<Certs> items){
super(context, resourceId, items);
this.context = context;
}
/*private view holder class*/
public class ViewHolder {
ImageView imageView;
TextView makeText;
ProgressBar mPB;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
//ViewHolder holder = null;
LayoutInflater mInflater = (LayoutInflater) context.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = mInflater.inflate(R.layout.item_view, null);
holder = new ViewHolder();
holder.makeText = (TextView) convertView.findViewById(R.id.item_txtName);
holder.imageView = (ImageView) convertView.findViewById(R.id.item_icon);
holder.mPB = (ProgressBar) convertView.findViewById(R.id.progress);
//holder.mPB.getIndeterminateDrawable().setColorFilter(0xFF4b86bb, android.graphics.PorterDuff.Mode.DST);
convertView.setTag(holder);
} else{
holder = (ViewHolder) convertView.getTag();
}
Certs currentCert = myCerts.get(position);
holder.makeText.setText(currentCert.getName().toString());
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/calligraphic.ttf");
holder.makeText.setTypeface(face);
holder.imageView.setImageResource(currentCert.getIconID());
//holder.mPB.setProgress(10);
holder.mPB.setId(currentCert.getPbID());
return convertView;
}
}
通过这段代码我可以膨胀布局,但我不想在这里使用列表视图。我想要几个图像和不同行中的文本将显示在相同的线性布局上而不使用列表视图。
答案 0 :(得分:0)
是的,有可能这样做。我创建了像你这样的相关代码......
package com.android.customlayout;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
public class MainActivity extends Activity implements OnClickListener {
private Button mAddButton;
private Button mDeleteButton;
private LinearLayout mLinear;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mAddButton = (Button) findViewById(R.id.add_button);
mDeleteButton = (Button) findViewById(R.id.delete_button);
mLinear = (LinearLayout) findViewById(R.id.child_linear);
mAddButton.setOnClickListener(this);
mDeleteButton.setOnClickListener(this);
}
@Override
public void onClick(View v) {
switch(v.getId()) {
case R.id.add_button :
View childView = getLayoutInflater().inflate(R.layout.custom_layout, null);
mLinear.addView(childView);
break;
case R.id.delete_button :
int childSize = mLinear.getChildCount();
if(childSize != 0) {
mLinear.removeViewAt(childSize - 1);
}
break;
}
}
}
在主xml中:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<Button
android:id="@+id/add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginLeft="29dp"
android:text="Add" />
<Button
android:id="@+id/delete_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="36dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="@id/add_button"
android:text="Delete" />
<LinearLayout android:id="@+id/child_linear"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="@id/add_button"
android:layout_marginTop="45dp"
android:orientation="vertical" >
</LinearLayout>
</RelativeLayout>
创建另一个名为custom Layout.xml的xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/editText1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10" />
</LinearLayout>
希望这会有所帮助.. :)
答案 1 :(得分:0)
要在listview的ImageView中加载图片,而不是尝试按照
<强> Library for async image loading and caching on Android 强>