【问题标题】:How to set the gravity of image view in a listview programatically?如何以编程方式在列表视图中设置图像视图的重力?
【发布时间】:2015-05-26 06:38:21
【问题描述】:

我以编程方式将 textview 安排到列表视图的左侧?但是在图像视图的情况下,它没有发生。为什么?下面给出了图像视图的代码。如何将其设置到列表视图的左侧.我试过了

tr.setGravity(Gravity.LEFT);    

这个但仍然是图像视图在中心

tr = new TableRow(AAAView.this);

                    tr.setWeightSum(2);
                    tr.setLayoutParams(param3);
                    tr.setGravity(Gravity.LEFT);                        
                    final ImageView b16513 = new ImageView(AAAView.this);

                    b16513.setLayoutParams(param1);
                    b16513.setTag(getAAADetails.datalist.get(i).Assist_Comp_Mobile);
                    b16513.setImageResource(R.drawable.callbutton);

                    b16513.setOnClickListener(new OnClickListener() {

                        @Override
                        public void onClick(View v) {
                            // TODO Auto-generated method stub
                            Intent intent = new Intent(Intent.ACTION_CALL,
                                    Uri.parse("tel:"
                                            + b16513.getTag().toString()));
                            startActivity(intent);
                        }
                    });




param1 = new TableRow.LayoutParams(
            android.widget.TableRow.LayoutParams.WRAP_CONTENT,
            android.widget.TableRow.LayoutParams.WRAP_CONTENT, 1);
    param2 = new TableRow.LayoutParams(
            android.widget.LinearLayout.LayoutParams.MATCH_PARENT,
            android.widget.LinearLayout.LayoutParams.WRAP_CONTENT, 1);
    param3 = new TableRow.LayoutParams(
            android.widget.LinearLayout.LayoutParams.MATCH_PARENT,
            android.widget.LinearLayout.LayoutParams.MATCH_PARENT, 1);
    param1.setMargins(1, 0, 1, 1);
    param2.setMargins(10, 0, 5, 1);

【问题讨论】:

  • 你的 imageView 布局参数是 wrap_content 吗?

标签: android listview imageview alignment


【解决方案1】:

如果您使用重力,按钮内的文本/图像将被放置在左侧(在其视图内)。 layout_gravity 在其容器内移动视图。尝试使用它。

如果我在这里弄错了,我很抱歉,但请尝试一下。

【讨论】:

    猜你喜欢
    • 2012-05-08
    • 1970-01-01
    • 2012-05-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多