Android 如何手动设置文本视图填充?
这是javaAndroid 如何手动设置文本视图填充?,android,textview,Android,Textview,这是java 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"
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>
在这个xml中,我还有其他对象,如图像视图和文本视图等
我这样设置,但它不会从左侧移动100
我认为在你的xml文件中,你应该让你的
TextViewwidth到fill\u parent
如果它是wrap\u content
我认为在你的xml文件中,你应该让你的TextViewwidth到fill\u parent
如果它是wrap\u content
首先,我决不会这样做。
如果您想以编程方式更改填充等,我也总是以编程方式添加视图。
我想是这样说的
您是否试图强制它使用.Invalidate()更新视图?首先,我绝不会这样做。
如果您想以编程方式更改填充等,我也总是以编程方式添加视图。
我想是这样说的
您是否试图强制它使用.Invalidate()更新视图?更改边距,而不是填充
编辑:来,让我来帮你
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);
更改边距而不是填充
编辑:来,让我来帮你
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);
如果你想根据我的知识移动它,请设置边距而不是填充
(尽可能使用dp而不是px,这只是一个建议。):) 如果您想根据我的知识移动它,请将其边距设置为不填充
(尽可能使用dp而不是px,这只是一个建议。):) 可以为整个布局添加xml吗?我怀疑这就是问题所在。为什么不在XML文件中设置它?@Thepoosh,很抱歉更新太晚,请看一看,这是整个XML。您可以为整个布局添加XML吗?我怀疑这就是问题所在为什么不在XML文件中设置它?@Thepoosh,很抱歉更新太晚,请看一看,这是整个xmla快速搜索将导致此stackoverflow线程:这是linearlayout,但我不是。事实上,在linearlayout中,我仍然得到了textview和imageviewcheck(来自Mauro)票数最多的答案,而不是被接受的答案。我肯定它符合你的情况。我编辑了答案。检查setLayoutParams方法-应该正是您需要的。小心-填充与边距不同。在CSS术语中,填充使视图变大,边距使视图之间的距离变大。快速搜索将导致此stackoverflow线程:该线程是linearlayout,但我不是。事实上,在linearlayout中,我仍然得到了textview和imageviewcheck(来自Mauro)票数最多的答案,而不是被接受的答案。我肯定它符合你的情况。我编辑了答案。检查setLayoutParams方法-应该正是您需要的。小心-填充与边距不同。在CSS术语中,填充使视图变大,边距使视图之间的距离变大。