2012-05-07 17 views
0

は、これは、このXMLでテキストビューのパディングを手動で設定する方法は?

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

ここalllatestnewslist.xml

<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> 

javaのですが、私は他の人がその上のイメージ図とTextViewのようなオブジェクトがあります。

他の方法を、私はこのように設定するが、それは離れて、左から100を移動させない........................

を?? ????????????????????

+0

レイアウト全体のxmlを追加できますか?私は問題がどこにあるのだろうと思っています – thepoosh

+0

なぜあなたはXMLファイルでそれを設定しませんか? –

+0

私が得たelse文 –

答えて

6

パディングの代わりに、余白を変更します。

編集:ここでは、あなたのためにやってみましょう。あなたは私の知識に従って、それを移動したい場合は

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); 
+0

クイック検索は、このstackoverflowのにつながる –

+0

をsetmargin持っていない動作しません。スレッド:http://stackoverflow.com/questions/2481455/set-margins-in-a-linearlayout-programmatically – josephus

+0

私はlinearlayoutですが、私はそうではありません。実際に直線レイアウトでは、私はまだテキストビューと画像ビュー –

0

私はあなたのxmlファイルにあなたはそれがすべてのwrap_content

+0

であれば、 –

0

まずあるならば、私はこのようにそれを行うことはないfill_parentにごTextView幅を作るべきだと思います。 パディングなどをプログラムで変更したい場合は、常にプログラマチックなビューを追加することもできます。 そう思っていました。

強制的にビューを.Invalidate()で更新しようとしましたか?

+0

が試みfill_parentで、 –

0

は(使用DPの代わりに、PX、可能な限りそのわずかの提案)...

をその余裕はないパディングを設定します。 :)

関連する問題