0

This is java

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

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>

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

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

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

Alan Lai
  • 1,094
  • 7
  • 18
  • 41

4 Answers4

6

Instead of padding, change the margin.

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);
josephus
  • 8,284
  • 1
  • 37
  • 57
  • a quick search would result to this stackoverflow thread: http://stackoverflow.com/questions/2481455/set-margins-in-a-linearlayout-programmatically – josephus May 07 '12 at 08:08
  • that one is linearlayout but i am not. Actually in the linearlayout, i still got textview and imageview – Alan Lai May 07 '12 at 08:37
  • check out the answer with the most votes (from Mauro), instead of the accepted answer. I'm positive it fits to your situation. – josephus May 07 '12 at 08:45
  • I edited the answer. Check out the setLayoutParams method - should be exactly what you need. – josephus May 07 '12 at 08:51
  • still cannot. `LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams( LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); layoutParams.setMargins(100, 0, 0, 0); // margins as you wish maintitle = (TextView) findViewById(R.id.text_particularlatestnewstitle); maintitle.setLayoutParams(layoutParams);` – Alan Lai May 07 '12 at 09:56
  • 2
    Careful - padding is not the same as margin. In CSS terms, padding makes the View bigger, margin makes the distance between Views bigger. – abergmeier Dec 22 '12 at 12:29
0

I think in your xml file you should make your TextView width to fill_parent if it is wrap_content

Lucifer
  • 29,392
  • 25
  • 90
  • 143
AndroidDev
  • 4,521
  • 24
  • 78
  • 126
0

First of all, I would never do it like this. If you want to change padding etc. programmatically I'd always add the view programmatical aswell. Thought that being said.

Have you tried to force it to update your view with .Invalidate() ?

Anders Metnik
  • 6,096
  • 7
  • 40
  • 79
0

set its margin not padding if you want to move it as per my knowledge...

(Use dp instead of px wherever possible its just a suggestion). :)

Shashank Degloorkar
  • 3,151
  • 4
  • 32
  • 50