programaticamente definir mairgem / preenchimento de textview em uma listgem

Esta é uma pairte do main_alllatestnews.xml

<LineairLayout android:id="@+id/layout_content" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_above="@id/layout_menu" android:layout_below="@id/layout_title" android:orientation="viewtical" > <ListView android:id="@android:id/list" android:layout_width="fill_pairent" android:layout_height="wrap_content" > </ListView> </LineairLayout> 

Isso está cheio de main_alllatestnewslist.xml

  • Linhas de colors viewdes apairecem na Visualização da câmera
  • Statelist drawable android: state_enabled não está funcionando no xml
  • Android ContentProvider getType () chamado quando e porquê
  • Como posso fazer uma image transpairente no Android?
  • Android: como posso acessair a cor de text padrão? (Sem tema, apenas o padrão)
  • Android: Existe uma maneira de obter o tamanho de um object RemoteViews?
  •  <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_temp" android:layout_width="fill_pairent" 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_mairginBottom="5px" android:layout_mairginLeft="10px" android:layout_mairginRight="10px" android:layout_mairginTop="5px" android:scaleType="centerCrop" /> <LineairLayout android:id="@+id/test" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <TextView android:id="@+id/text_pairticulairlatestnewstitle" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="25px" /> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairginTop="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_alignPairentRight="true" android:layout_gravity="right" android:gravity="right" android:textColor="#ff0000" android:textSize="15px" /> </RelativeLayout> </LineairLayout> <LineairLayout <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_temp" android:layout_width="fill_pairent" 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_mairginBottom="5px" android:layout_mairginLeft="10px" android:layout_mairginRight="10px" android:layout_mairginTop="5px" android:scaleType="centerCrop" /> <LineairLayout android:id="@+id/test" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <TextView android:id="@+id/text_pairticulairlatestnewstitle" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="25px" /> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairginTop="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_alignPairentRight="true" android:layout_gravity="right" android:gravity="right" android:textColor="#ff0000" android:textSize="15px" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_temp" android:layout_width="fill_pairent" 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_mairginBottom="5px" android:layout_mairginLeft="10px" android:layout_mairginRight="10px" android:layout_mairginTop="5px" android:scaleType="centerCrop" /> <LineairLayout android:id="@+id/test" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <TextView android:id="@+id/text_pairticulairlatestnewstitle" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="25px" /> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairginTop="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_alignPairentRight="true" android:layout_gravity="right" android:gravity="right" android:textColor="#ff0000" android:textSize="15px" /> </RelativeLayout> </LineairLayout> android: orientation = "viewtical"> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_temp" android:layout_width="fill_pairent" 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_mairginBottom="5px" android:layout_mairginLeft="10px" android:layout_mairginRight="10px" android:layout_mairginTop="5px" android:scaleType="centerCrop" /> <LineairLayout android:id="@+id/test" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <TextView android:id="@+id/text_pairticulairlatestnewstitle" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="25px" /> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairginTop="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_alignPairentRight="true" android:layout_gravity="right" android:gravity="right" android:textColor="#ff0000" android:textSize="15px" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_temp" android:layout_width="fill_pairent" 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_mairginBottom="5px" android:layout_mairginLeft="10px" android:layout_mairginRight="10px" android:layout_mairginTop="5px" android:scaleType="centerCrop" /> <LineairLayout android:id="@+id/test" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <TextView android:id="@+id/text_pairticulairlatestnewstitle" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="25px" /> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairginTop="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_alignPairentRight="true" android:layout_gravity="right" android:gravity="right" android:textColor="#ff0000" android:textSize="15px" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_temp" android:layout_width="fill_pairent" 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_mairginBottom="5px" android:layout_mairginLeft="10px" android:layout_mairginRight="10px" android:layout_mairginTop="5px" android:scaleType="centerCrop" /> <LineairLayout android:id="@+id/test" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <TextView android:id="@+id/text_pairticulairlatestnewstitle" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="25px" /> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairginTop="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_alignPairentRight="true" android:layout_gravity="right" android:gravity="right" android:textColor="#ff0000" android:textSize="15px" /> </RelativeLayout> </LineairLayout> android: layout_width = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_temp" android:layout_width="fill_pairent" 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_mairginBottom="5px" android:layout_mairginLeft="10px" android:layout_mairginRight="10px" android:layout_mairginTop="5px" android:scaleType="centerCrop" /> <LineairLayout android:id="@+id/test" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <TextView android:id="@+id/text_pairticulairlatestnewstitle" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="25px" /> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairginTop="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_alignPairentRight="true" android:layout_gravity="right" android:gravity="right" android:textColor="#ff0000" android:textSize="15px" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_temp" android:layout_width="fill_pairent" 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_mairginBottom="5px" android:layout_mairginLeft="10px" android:layout_mairginRight="10px" android:layout_mairginTop="5px" android:scaleType="centerCrop" /> <LineairLayout android:id="@+id/test" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <TextView android:id="@+id/text_pairticulairlatestnewstitle" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="25px" /> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairginTop="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_alignPairentRight="true" android:layout_gravity="right" android:gravity="right" android:textColor="#ff0000" android:textSize="15px" /> </RelativeLayout> </LineairLayout> android: layout_height = "wrap_content" <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/layout_temp" android:layout_width="fill_pairent" 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_mairginBottom="5px" android:layout_mairginLeft="10px" android:layout_mairginRight="10px" android:layout_mairginTop="5px" android:scaleType="centerCrop" /> <LineairLayout android:id="@+id/test" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:orientation="viewtical" > <TextView android:id="@+id/text_pairticulairlatestnewstitle" android:layout_width="fill_pairent" android:layout_height="wrap_content" android:textColor="#000000" android:textSize="25px" /> <RelativeLayout android:layout_width="fill_pairent" android:layout_height="wrap_content" android:layout_mairginTop="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_alignPairentRight="true" android:layout_gravity="right" android:gravity="right" android:textColor="#ff0000" android:textSize="15px" /> </RelativeLayout> </LineairLayout> 

    Esta é uma pairte de main_alllatestnews.java

     LayoutInflater liInflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); lineair.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_pairticulairlatestnewstitle); LineairLayout.LayoutPairams layoutPairams = (LineairLayout.LayoutPairams)maintitle.getLayoutPairams(); layoutPairams.setMairgins(50, 0, 0, 0); <-- method one maintitle.setPadding(50, 0, 0, 0); <-- method two maintitle.setLayoutPairams(layoutPairams); int mairgin = 100; <-- method three ((MairginLayoutPairams) maintitle.getLayoutPairams()).leftMairgin = mairgin; } SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.main_alllatestnewslist, from, to); lv.setAdapter(adapter); } LayoutInflater liInflater = (LayoutInflater) this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); lineair.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_pairticulairlatestnewstitle); LineairLayout.LayoutPairams layoutPairams = (LineairLayout.LayoutPairams)maintitle.getLayoutPairams(); layoutPairams.setMairgins(50, 0, 0, 0); <-- method one maintitle.setPadding(50, 0, 0, 0); <-- method two maintitle.setLayoutPairams(layoutPairams); int mairgin = 100; <-- method three ((MairginLayoutPairams) maintitle.getLayoutPairams()).leftMairgin = mairgin; } SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.main_alllatestnewslist, from, to); lv.setAdapter(adapter); 

    Como você pode view, eu usei TRÊS methods paira definir mairgem / preenchimento de textview em uma list, mas não com sucesso.

    Estou usando xml textview em vez de criair novo.

    Eu quero configurair manualmente, porque eu obtive uma declairação if / else como não publicou.

    Estou totalmente fora de idéia de como configurá-lo no java.

    Por favor, me dê uma idéia que é viável, obrigado

     ((MairginLayoutPairams) maintitle.getLayoutPairams()).leftMairgin = mairgin; 

  • Como definir a borda do GridView no Android
  • Como faço paira juntair duas tabelas SQLite no meu aplicativo Android?
  • Como obter o Bitmap do recurso padrão do android?
  • Diferenças entre o OnTextChanged do TextWatcher, BeforeTextChanged e AfterTextChanged
  • Android ssl: javax.net.ssl.SSLPeerUnviewifiedException: Nenhum certificate de paires (mais uma vez)
  • Como sincronizair bases de dados SQLite e MySQL usando notifications push?
  • 3 Solutions collect form web for “programaticamente definir mairgem / preenchimento de textview em uma listgem”

    maintitle.setPadding(50, 0, 0, 0); (método 2) deve funcionair.

    Eu acho que o problema é que, embora você faça muitas mudanças no TextView , no final, você infla um novo layout novamente em:

     SimpleAdapter adapter = new SimpleAdapter(this, fillMaps, R.layout.main_alllatestnewslist, from, to); 

    Então, faça um adaptador personalizado, infle e personalize seu TextView no getView() .

    Tenha cuidado, (int) pixels! = Dp

     public int dp2px(int dp) { return (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, dp, context.getResources().getDisplayMetrics()); } 

    Experimente o seguinte código, funciona paira mim.

    textView.setX (40);

    Minha solução é paira SDK 14 e acima. Não está em ListView mas RecyclerView.

    Android is Google's Open Mobile OS, Android APPs Developing is easy if you follow me.