android 填充内存方法,android - 以编程方式在列表视图中设置textview的边距/填充 - 堆栈内存溢出...

这是main_alllatestnews.xml的一部分

android:id="@+id/layout_content"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_above="@id/layout_menu"

android:layout_below="@id/layout_title"

android:orientation="vertical" >

android:id="@android:id/list"

android:layout_width="fill_parent"

android:layout_height="wrap_content" >

这里充满了main_alllatestnewslist.xml

android:id="@+id/layout_temp"

android:layout_width="fill_parent"

android:layout_height="100px"

android:background="@drawable/background_news_list" >

android:id="@+id/image_alllatestnewstitle"

android:layout_width="134px"

android:layout_height="80px"

android:layout_marginBottom="5px"

android:layout_marginLeft="10px"

android:layout_marginRight="10px"

android:layout_marginTop="5px"

android:scaleType="centerCrop" />

android:id="@+id/test"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:orientation="vertical" >

android:id="@+id/text_particularlatestnewstitle"

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:textColor="#000000"

android:textSize="25px" />

android:layout_width="fill_parent"

android:layout_height="wrap_content"

android:layout_marginTop="25px" >

android:id="@+id/text_newsdate"

android:layout_width="wrap_content"

android:layout_height="wrap_content"

android:textColor="#999999"

android:textSize="15px" />

android:id="@+id/text_newscategorytitle"

android:layout_width="50px"

android:layout_height="wrap_content"

android:layout_alignParentRight="true"

android:layout_gravity="right"

android:gravity="right"

android:textColor="#ff0000"

android:textSize="15px" />

这是main_alllatestnews.java的一部分

LayoutInflater liInflater = (LayoutInflater) this

.getSystemService(Context.LAYOUT_INFLATER_SERVICE);

linear.addView(liInflater

.inflate(R.layout.main_alllatestnewslist, null));

lv = (ListView) findViewById(android.R.id.list);

for (int i = 0; i < webservice.news.size(); i++) {

maintitle = (TextView) findViewById(R.id.text_particularlatestnewstitle);

LinearLayout.LayoutParams layoutParams = (LinearLayout.LayoutParams)maintitle.getLayoutParams();

layoutParams.setMargins(50, 0, 0, 0);

maintitle.setPadding(50, 0, 0, 0);

maintitle.setLayoutParams(layoutParams);

int margin = 100;

((MarginLayoutParams) maintitle.getLayoutParams()).leftMargin = margin;

}

SimpleAdapter adapter = new SimpleAdapter(this, fillMaps,

R.layout.main_alllatestnewslist, from, to);

lv.setAdapter(adapter);

正如您所看到的,我使用了三种方法在列表视图中设置textview的边距/填充但不成功。

我使用的是xml textview而不是create new。

我想手动设置,因为我得到if / else语句,因为没有发布。

我完全不知道如何在java中设置它。

请给我一个可行的想法,谢谢

((MarginLayoutParams) maintitle.getLayoutParams()).leftMargin = margin;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值