1

これは私のカスタムアダプターのコードです (ブラウンカラーのコード) 最初にリストがビルドされたとき、下にスクロールして再度上にスクロールすると、有効な項目に適切なマージンが適用されますリストのすべての行はマージンを20左にシフトします間違っています すぐに返信してください

@Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;
        // getting data
        final ViewMovieDetailsModel_ViewComments movies = getItem(position);

        if (convertView == null) 
        {
            convertView = View.inflate(context, R.layout.comment_row, null);                
            holder = new ViewHolder();

            //getting handles

            holder.comments_linearLayout = (LinearLayout) convertView.findViewById(R.id.comments_linearLayout);
            holder.commenter_textView = (TextView) convertView.findViewById(R.id.comment_row_commenter);
            holder.commented_on_textView = (TextView) convertView.findViewById(R.id.comment_row_comment_time);
            holder.comment_text_textView = (TextView) convertView.findViewById(R.id.comment_row_comment_text);
            holder.reply_button = (Button) convertView.findViewById(R.id.comment_row_reply_button);

            convertView.setTag(holder);
        }
        else
        {
            holder = (ViewHolder)convertView.getTag();
        }

        if (movies != null) 
        {
            if (((movies.getParent_comment_id()).toString().equals("null")) && session.isLoggedIn()==true) {
                holder.reply_button.setVisibility(View.VISIBLE);
            }else{
                holder.reply_button.setVisibility(View.INVISIBLE);
            }


`if (!((movies.getParent_comment_id()).toString().equals("null"))) 
{

LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.WRAP_CONTENT);
                    params.setMargins(20, 0, 0, 0);
                    holder.comments_linearLayout.setLayoutParams(params);
}`


            holder.commenter_textView.setText(movies.getUsername_commentor());

            holder.commenter_textView.setTag(movies.getUser_id_commentor());

        return convertView;
    }
4

2 に答える 2

0

「if」ステートメントでマージン(茶色のフォント)を設定しているため:

if (movies != null)

このifブロックから取り出すだけです(たとえば、リターンポイントの直前に置きます)

現時点では、ムービーが null であるため、このコードはおそらく最初のビューの読み込み時に実行されません。getView が 2 回目に呼び出されると、ムービーは null ではなく、「ブラウン」コードに従ってマリジンが設定されます。

これが解決策でない場合 - 内部の if ステートメントの条件が真でない可能性があります (最初の「茶色」の行にあるもの)。だから..あなた自身のロジックは、あなたが望むようにマリジンが設定されるのを防ぎます:)

それが役立つかどうか私に知らせてください。

于 2013-06-29T16:09:53.093 に答える