簡體   English   中英

如何以編程方式將LinearLayout放置在屏幕的右側?

[英]How to programmatically make a LinearLayout placed in the right side of the screen?

我有一個通過程序生成的圖像和文本視圖,但是我遇到了以下問題,如何使LinearLayout邊距成為父級

 LinearLayout lin = (LinearLayout) convertView.findViewById(R.id.linearChat);
 final ImageView img1 = new ImageView(context);
 final TextView tv1 = new TextView(context);
 tv1.setText(chat.getPesan());
        img1.setImageDrawable(context.getResources().getDrawable(R.drawable.cservice));
        lin.addView(tv1);
        tv1.setBackgroundResource(R.drawable.rounded_corner1);
        tv1.setPadding(10,10,10,10);
        lin.addView(img1);

添加setMargin()行,

// Left Top Right Bottom Margin
tv1.setMargins(25,25,25,25);  // adjust according to your need

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM