本文整理汇总了Java中android.widget.GridView.setLayoutParams方法的典型用法代码示例。如果您正苦于以下问题:Java GridView.setLayoutParams方法的具体用法?Java GridView.setLayoutParams怎么用?Java GridView.setLayoutParams使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.widget.GridView
的用法示例。
在下文中一共展示了GridView.setLayoutParams方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createEmotionGridView
import android.widget.GridView; //导入方法依赖的package包/类
/**
* 创建显示表情的GridView
*/
private GridView createEmotionGridView(List<String> emotionNames, int gvWidth, int padding, int itemWidth, int gvHeight) {
// 创建GridView
GridView gv = new GridView(getActivity());
//设置点击背景透明
gv.setSelector(android.R.color.transparent);
//设置7列
gv.setNumColumns(7);
gv.setPadding(padding, padding, padding, padding);
gv.setHorizontalSpacing(padding);
gv.setVerticalSpacing(padding * 2);
//设置GridView的宽高
ViewGroup.LayoutParams params = new ViewGroup.LayoutParams(gvWidth, gvHeight);
gv.setLayoutParams(params);
// 给GridView设置表情图片
EmotionGridViewAdapter adapter = new EmotionGridViewAdapter(getActivity(), emotionNames, itemWidth,emotion_map_type);
gv.setAdapter(adapter);
//设置全局点击事件
gv.setOnItemClickListener(GlobalOnItemClickManagerUtils.getInstance().getOnItemClickListener(getActivity(),emotion_map_type));
return gv;
}
示例2: getViewPagerItem
import android.widget.GridView; //导入方法依赖的package包/类
private GridView getViewPagerItem(final int index) {
GridView gridView = new GridView(_context);
gridView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
gridView.setNumColumns(4);
gridView.setVerticalScrollBarEnabled(false);
gridView.setHorizontalScrollBarEnabled(false);
gridView.setPadding(8, 8, 8, 0);
gridView.setVerticalSpacing(20);
gridView.setSelector(new ColorDrawable(Color.TRANSPARENT));
gridView.setAdapter(new YayaEmoGridViewAdapter(_context,
getGridViewData(index)));
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
int start = index * SysConstant.yayaPageSize;
onEmoGridViewItemClick.onItemClick(position + start, index);
}
});
return gridView;
}
示例3: setGridViewHeightByChildren
import android.widget.GridView; //导入方法依赖的package包/类
/**
* 根据子item的高度 动态测量GridView的实际高度
* @param gridView
*/
public static void setGridViewHeightByChildren(GridView gridView) {
ListAdapter listAdapter = gridView.getAdapter();
if (listAdapter == null) {
return;
}
//总高度
int totalHeight = 0;
int lineNum = gridView.getNumColumns(); //得到布局文件中设置的一行显示几个
View item = listAdapter.getView(0,null,gridView);
item.measure(0,0); //计算子item的高度
//得到总高度
totalHeight = item.getMeasuredHeight()*lineNum;
ViewGroup.LayoutParams params = gridView.getLayoutParams();
params.height = totalHeight;
gridView.setLayoutParams(params);
}
示例4: getViewPagerItem
import android.widget.GridView; //导入方法依赖的package包/类
private GridView getViewPagerItem(final int index) {
GridView gridView = new GridView(_context);
gridView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT));
gridView.setNumColumns(7);
gridView.setVerticalScrollBarEnabled(false);
gridView.setHorizontalScrollBarEnabled(false);
gridView.setPadding(8, 8, 8, 0);
gridView.setVerticalSpacing(CommonUtil.getElementSzie(_context) / 2
+ CommonUtil.getElementSzie(_context) / 3);
// gridView.setVerticalSpacing(30);
gridView.setBackgroundColor(Color.TRANSPARENT);
gridView.setAdapter(new EmoGridViewAdapter(_context,
getGridViewData(index)));
gridView.setOnItemClickListener(new OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
int start = index * (SysConstant.pageSize - 1);
onEmoGridViewItemClick.onItemClick(position + start, index);
}
});
return gridView;
}
示例5: setGridViewHeightBasedOnChildren
import android.widget.GridView; //导入方法依赖的package包/类
public static void setGridViewHeightBasedOnChildren(GridView gridView, int colNum) {
ListAdapter listAdapter = gridView.getAdapter();
if (listAdapter == null) {
// pre-condition
return;
}
int totalHeight = 0;
int lines = (int) Math.ceil((double) listAdapter.getCount() / colNum);
for (int i = 0; i < lines; i++) {
View listItem = listAdapter.getView(i, null, gridView);
listItem.measure(0, 0);
totalHeight += listItem.getMeasuredHeight();
}
ViewGroup.LayoutParams params = gridView.getLayoutParams();
params.height = totalHeight + (gridView.getVerticalSpacing() * (lines - 1));
gridView.setLayoutParams(params);
}
示例6: setGridViewHeightBasedOnChildren
import android.widget.GridView; //导入方法依赖的package包/类
public static void setGridViewHeightBasedOnChildren(GridView listView,int col) {
// 获取listview的adapter
ListAdapter listAdapter = listView.getAdapter();
if (listAdapter == null) {
return;
}
// 固定列宽,有多少列
int totalHeight = 0;
// i每次加4,相当于listAdapter.getCount()小于等于4时 循环一次,计算一次item的高度,
// listAdapter.getCount()小于等于8时计算两次高度相加
for (int i = 0; i < listAdapter.getCount(); i += col) {
// 获取listview的每一个item
View listItem = listAdapter.getView(i, null, listView);
listItem.measure(0, 0);
// 获取item的高度和
totalHeight += listItem.getMeasuredHeight();
totalHeight += listView.getVerticalSpacing();
if (i==listAdapter.getCount()-1) {
totalHeight += listView.getVerticalSpacing();
}
}
// 获取listview的布局参数
LayoutParams params = listView.getLayoutParams();
// 设置高度
params.height = totalHeight;
// 设置margin
((MarginLayoutParams) params).setMargins(10, 10, 10, 10);
// 设置参数
listView.setLayoutParams(params);
}
示例7: onCreateView
import android.widget.GridView; //导入方法依赖的package包/类
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
provider = getArguments().getParcelable(ARG_PROVIDER);
String result = getSQLResult(getContext(), provider, getString(R.string.sql_injection));
View rootView = inflater.inflate(R.layout.fragment_details_schema, container, false);
if (getStatus(result)==100){
//TODO add image view
rootView.findViewById(R.id.tv_schema).setVisibility(View.VISIBLE);
} else {
LinearLayout linearLayout = (LinearLayout) rootView.findViewById(R.id.ll);
Map<String, List<List<String>>> resultToMap = parseResultToMap(result);
for (String name: resultToMap.keySet()){
TextView tv = getFilledTextView(getContext(),name);
linearLayout.addView(tv);
GridView grid = new GridView(getContext());
grid.setNumColumns(3);
grid.setHorizontalSpacing(10);
grid.setVerticalSpacing(10);
grid.setStretchMode(GridView.STRETCH_COLUMN_WIDTH);
grid.setGravity(View.TEXT_ALIGNMENT_CENTER);
List<List<String>> list = resultToMap.get(name);
grid.setAdapter(new GridAdapter(getContext(),list));
grid.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, list.size()*35)); //TODO: remove int value
linearLayout.addView(grid);
}
}
return rootView;
}
示例8: init
import android.widget.GridView; //导入方法依赖的package包/类
private void init(){
cal = Calendar.getInstance();
base = new RelativeLayout(context);
base.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT));
base.setMinimumHeight(50);
base.setId(4);
LayoutParams params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.leftMargin = 16;
params.topMargin = 50;
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.addRule(RelativeLayout.CENTER_VERTICAL);
prev = new ImageView(context);
prev.setId(1);
prev.setLayoutParams(params);
prev.setImageResource(R.drawable.navigation_previous_item);
prev.setOnClickListener(this);
base.addView(prev);
params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
params.addRule(RelativeLayout.CENTER_VERTICAL);
month = new TextView(context);
month.setId(2);
month.setLayoutParams(params);
month.setTextAppearance(context, android.R.attr.textAppearanceLarge);
month.setText(cal.getDisplayName(Calendar.MONTH, Calendar.LONG, Locale.getDefault())+" "+cal.get(Calendar.YEAR));
month.setTextSize(25);
base.addView(month);
params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.rightMargin = 16;
params.topMargin = 50;
params.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
params.addRule(RelativeLayout.CENTER_VERTICAL);
next = new ImageView(context);
next.setImageResource(R.drawable.navigation_next_item);
next.setLayoutParams(params);
next.setId(3);
next.setOnClickListener(this);
base.addView(next);
addView(base);
params = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params.bottomMargin = 20;
params.addRule(RelativeLayout.ALIGN_PARENT_LEFT);
params.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
params.addRule(RelativeLayout.BELOW, base.getId());
calendar = new GridView(context);
calendar.setLayoutParams(params);
calendar.setVerticalSpacing(4);
calendar.setHorizontalSpacing(4);
calendar.setNumColumns(7);
calendar.setChoiceMode(GridView.CHOICE_MODE_SINGLE);
calendar.setDrawSelectorOnTop(true);
calendar.setFocusable(false);
mAdapter = new CalendarAdapter(context,cal);
calendar.setAdapter(mAdapter);
calendar.setOnTouchListener(new OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return calendarGesture.onTouchEvent(event);
}
});
addView(calendar);
}
示例9: initViews
import android.widget.GridView; //导入方法依赖的package包/类
private void initViews() {
mBtnBack = (Button) findViewById(R.id.btn_puzzle_main_back);
mBtnImage = (Button) findViewById(R.id.btn_puzzle_main_img);
mBtnRestart = (Button) findViewById(R.id.btn_puzzle_main_restart);
//flag是否显示原图
mIsShowImg = false;
mGvPuzzleMainDetail = (GridView) findViewById(
R.id.gv_puzzle_main_detail);
// 设置为N*N显示
mGvPuzzleMainDetail.setNumColumns(TYPE);
RelativeLayout.LayoutParams gridParams = new RelativeLayout.LayoutParams(mPicSelected.getWidth(),mPicSelected.getHeight());
//水平居中
gridParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
//其他格式属性
gridParams.addRule(RelativeLayout.BELOW,R.id.ll_puzzle_main_spinner);
//Grid显示
mGvPuzzleMainDetail.setLayoutParams(gridParams);
mGvPuzzleMainDetail.setHorizontalSpacing(0);
mGvPuzzleMainDetail.setVerticalSpacing(0);
//TV步数
mTvPuzzleMainCounts = (TextView) findViewById(R.id.tv_puzzle_main_counts);
mTvPuzzleMainCounts.setText(""+ COUNT_INDEX);
//Tv计时器
mTvTimer = (TextView) findViewById(R.id.tv_puzzle_main_time);
mTvTimer.setText("0秒");
//添加显示的原图
addImgView();
}
示例10: setGridViewHeight
import android.widget.GridView; //导入方法依赖的package包/类
public void setGridViewHeight(GridView gridView) {
if (gridView == null) {
return;
}
ViewGroup.LayoutParams params = gridView.getLayoutParams();
//获取ActionBar高度
TypedValue tv = new TypedValue();
int actionBarHeight = 0;
if (mContext.getTheme().resolveAttribute(android.R.attr.actionBarSize, tv, true)) {
actionBarHeight = TypedValue.complexToDimensionPixelSize(tv.data, mContext.getResources().getDisplayMetrics());
}
/**
* 获取状态栏高度
* */
int statusBarHeight = 0;
if (getResources() != null) {
int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android");
if (resourceId > 0) {
//根据资源ID获取响应的尺寸值
statusBarHeight = getResources().getDimensionPixelSize(resourceId);
}
}
params.height = getScreenHeight() - getSolidHeight() - actionBarHeight - statusBarHeight;
// 设置参数
gridView.setLayoutParams(params);
}