我有一个DrawerLayout,我的DrawerLayout当前显示的是一个包含图像和文本的列表视图,一切都运行良好
现在,我决定在我的DrawerLayout中添加一个标题,并在listview中为几行添加一个特殊字段
谢谢
这张图片说明了我想做的事情:
http://8pic.ir/images/als4ye1elyo35tpju7hq.png
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/MainDrawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:id="@+id/MainDrawerFrame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
<ListView android:id="@+id/MainDrawerListView"
android:layout_width="270dp"
android:layout_height="match_parent"
android:layout_gravity="end"
android:divider="@null"
android:background="@color/DrawerBackGround" />
</android.support.v4.widget.DrawerLayout>
drawer_listview.xml
<?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="45dp">
<ImageView
android:id="@+id/DrawerIcon"
android:layout_width="45dp"
android:layout_height="45dp"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:layout_marginEnd="5dp"
android:layout_marginRight="5dp"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:contentDescription="@null"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:id="@+id/DrawerText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="18sp"
android:layout_centerVertical="true"
android:textColor="@color/DrawerFontColor"
android:layout_toLeftOf="@+id/DrawerIcon"
android:layout_toStartOf="@+id/DrawerIcon" />
</RelativeLayout>
CustomListAdapter.java
import android.app.Activity;
import android.graphics.Typeface;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.TextView;
public class CustomListAdapter extends ArrayAdapter<String>
{
private final Activity ActivityContext;
private final String[] ItemName;
private final Integer[] ImageID;
public CustomListAdapter(Activity context, String[] itemname, Integer[] imgid)
{
super(context, R.layout.drawer_listview, itemname);
this.ActivityContext = context;
this.ItemName = itemname;
this.ImageID = imgid;
}
@Override
public View getView(int position, View Unused1, ViewGroup Unused2)
{
LayoutInflater inflater = ActivityContext.getLayoutInflater();
View view = inflater.inflate(R.layout.drawer_listview, null);
ImageView DrawerIcon = (ImageView) view.findViewById(R.id.DrawerIcon);
TextView DrawerText = (TextView) view.findViewById(R.id.DrawerText);
Typeface FontFace = Typeface.createFromAsset(ActivityContext.getAssets(), "Yekan.ttf");
DrawerText.setTypeface(FontFace);
DrawerIcon.setImageResource(ImageID[position]);
DrawerText.setText(ItemName[position]);
return view;
};
}
MainActivity.java http://paste.ubuntu.com/15237990/
答案 0 :(得分:0)
当用户滚动列表视图时,您是否希望标题滚动到屏幕顶部?如果是这样,只需使用addHeaderView API将标题添加到列表视图中。
如果您希望标题保留在原位,请将其添加到XML
中Sub ParseJson()
Dim j As String, sc As Object, num As Long, i
j = Range("A1").Value 'I'm testing in excel...
Set sc = CreateObject("ScriptControl")
sc.Language = "JScript"
'evaluate the json to create a "response" object
sc.ExecuteStatement "var response = eval((" & j & "));"
'create a function to return us a piece of data
' based on the passed-in js fragment
sc.ExecuteStatement "var f = function(s){return eval(s);};"
'how many reviews ?
num = sc.Eval("f('response.reviews.length')") '>> 4
For i = 0 To num - 1
Debug.Print "------- Review " & i & "---------------"
Debug.Print sc.Eval("f('response.reviews[" & i & "].author')")
Debug.Print sc.Eval("f('response.reviews[" & i & "].title')")
'etc etc
Next i
End Sub