在GridView中移动应用程序图标下方的文本

时间:2013-02-06 14:55:28

标签: android list icons

Hello Guys如何在图标下方安排appname?如果你需要我给出来源。

enter image description here

您可以在此处查看用于创建此视图的代码:

package com.example.draw;

import java.util.List;

import android.content.Context;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

public class AppInfoAdapter extends BaseAdapter {
    private Context mContext;
    private List<ApplicationInfo> mListAppInfo;
    private PackageManager mPackManager;

    public AppInfoAdapter(Context c, List<ApplicationInfo> list, PackageManager pm) {
        mContext = c;
        mListAppInfo = list;
        mPackManager = pm;
    }

    @Override
    public int getCount() {
        return mListAppInfo.size();
    }

    @Override
    public Object getItem(int position) {
        return mListAppInfo.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        // get the selected entry
        ApplicationInfo entry = mListAppInfo.get(position);

        // reference to convertView
        View v = convertView;

        // inflate new layout if null
        if(v == null) {
            LayoutInflater inflater = LayoutInflater.from(mContext);
            v = inflater.inflate(R.layout.activity_appinfo, null);
        }

        // load controls from layout resources
        ImageView ivAppIcon = (ImageView)v.findViewById(R.id.ivIcon);



        // set data to display
        ivAppIcon.setImageDrawable(entry.loadIcon(mPackManager));



        // return view
        return v;
    }
}

文字来自      TextView tvAppName =(TextView)v.findViewById(R.id.tvName);    tvAppName.setText(entry.loadLabel(mPackManager));

main_appinfo.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="?android:attr/listPreferredItemHeight"
    android:orientation="horizontal"
    android:padding="5dip" >

  <ImageView
      android:id="@+id/ivIcon"
      android:layout_width="wrap_content"
      android:layout_height="fill_parent"
      android:layout_gravity="center"
      android:layout_weight="1"
      android:contentDescription="@string/desc"
      android:scaleType="center" 
      android:gravity="center_horizontal|center_vertical"/>

</LinearLayout>

2 个答案:

答案 0 :(得分:0)

布局文件中的LinearLayout水平,使其垂直。

android:orientation="horizontal"android:orientation="vertical"

答案 1 :(得分:-1)

应用程序图标和标题格式是android中主屏幕应用程序的一部分,您无法修改其外观。

如果您需要,您可以创建自己的主屏幕应用程序并随意使用它。

以下是主屏幕应用的示例:Home App Android sdk Sample