如何手动设置TextView的填充? [英] how to manually set textview padding?

查看:199
本文介绍了如何手动设置TextView的填充?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是用java

maintitle = (TextView)findViewById(R.id.text_particularlatestnewstitle);
maintitle.setPadding(100, 0, 0, 0);

alllatestnewslist.xml此处

alllatestnewslist.xml here

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout_temp"
android:layout_width="fill_parent"
android:layout_height="100px"
android:background="@drawable/background_news_list" >

<ImageView
    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" />

<LinearLayout
    android:id="@+id/test"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="5px"
    android:layout_marginLeft="100px"
    android:layout_marginRight="10px"
    android:layout_marginTop="5px"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/text_particularlatestnewstitle"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textColor="#000000"
        android:textSize="25px" />

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_marginTop="25px" >

        <TextView
            android:id="@+id/text_newsdate"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textColor="#999999"
            android:textSize="15px" />

        <TextView
            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" />
    </RelativeLayout>
</LinearLayout>

在此XML,我有其他类似物体图像视图和TextView的等等。

In this xml, i have others object like image view and textview so on.

我这样设置,但它不动100距左........................

I set like this but it does not move 100 away from left........................

任何其他方式???????????????????????

Any other way???????????????????????

推荐答案

,更改页边距。

编辑:在这里,让我为你做它

edit: here, let me do it for you.

LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(30, 20, 30, 0); // margins as you wish

TextView myTextView = findViewById(R.id.text_particularlatestnewstitle);
myTextView.setLayoutParams(layoutParams);

这篇关于如何手动设置TextView的填充?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆