0

I have created a dynamic TableLayout and I have given an image to TableRow's Background.But my problem is the image is taking its actual size not what I am setting.I want that image should take the height and width defined by me. Please Help Me.

My Code is...

void createRows()
{
    for(int i=0;i<5;i++)
    {
        String name = "Hareesh Kumar Gangadhara";
        String time = "2:53 PM";
        String date = "06/05/11";
        String time_date =time+" "+date;
        String message = "Hello Prashant";
        TableRow row_message = new TableRow(this);
        ImageView friend_img = new ImageView(this);
        LinearLayout layout_msg_info = new LinearLayout(this);
        LinearLayout layout_name_date = new LinearLayout(this);
        LinearLayout layout_message = new LinearLayout(this);

        friend_img.setLayoutParams(new LayoutParams(35,35));

        friend_img.setBackgroundResource(R.drawable.archit);

        TextView tv_name = new TextView(this);
        TextView tv_time_date = new TextView(this);
        TextView tv_message = new TextView(this);

        tv_name.setText(name);
        tv_time_date.setText(time_date);
        tv_message.setText(message);

        tv_name.setTextColor(color_black);
        tv_time_date.setTextColor(color_black);
        tv_message.setTextColor(color_black);


        tv_name.setTextSize(14);
        tv_time_date.setTextSize(10);
        tv_message.setTextSize(12);


        layout_name_date.addView(tv_name);
        layout_name_date.addView(tv_time_date);
        layout_message.addView(tv_message);

        layout_msg_info.setOrientation(LinearLayout.VERTICAL);

        layout_msg_info.setPadding(30, 10, 0, 0);
        layout_msg_info.addView(layout_name_date);
        layout_msg_info.addView(layout_message);

        row_message.setBackgroundResource(R.drawable.img_message_back);
        row_message.setLayoutParams(new TableRow.LayoutParams(LayoutParams.FILL_PARENT,40));
        row_message.setPadding(0, 0, 10, 5);
        row_message.addView(friend_img);
        row_message.addView(layout_msg_info);

        table_message.addView(row_message);

    }
}

2 Answers 2

2

Use TableRow.LayoutParams instead of ViewGroup.LayoutParams.

Hope it Helps

Sign up to request clarification or add additional context in comments.

Comments

0

You probably need to set the ScaleType value on your ImageView.

Here's the ScaleType reference: http://developer.android.com/reference/android/widget/ImageView.ScaleType.html

You're probably looking to set it to FIT_XY or CENTER_INSIDE.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.