我有一个非常基本的程序,它显示一个标准的 Textview 和一个扩展的 Textview。扩展的将被膨胀到主布局中。现在每次我添加一个新的扩展文本视图时,它看起来都很好,但我也希望它们之间有一些差距。这可能意味着我必须为我的 xml 文件添加边距。谁能帮助我如何实现这一目标?
编辑:我尝试在我的主布局文件中添加适当的标签(android:layout_marginBottom="25dip"),但间隙不会显示。请检查我的源代码并帮助我。问候
这是我的程序的源代码:
ExpenseWatchActivity.java(这是主要的Activity)
package com.app.expensewatch;
import android.app.Activity;
import android.os.Bundle;
import android.widget.LinearLayout;
import android.widget.TextView;
import java.util.Calendar;
import android.view.LayoutInflater;
import android.content.Context;
public class ExpenseWatchActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout ll = (LinearLayout)findViewById(R.id.mainlayout);
int day,mon,yr;
Calendar cal = Calendar.getInstance();
day = cal.get(Calendar.DATE);
mon = 1 + cal.get(Calendar.MONTH);
yr = cal.get(Calendar.YEAR);
String text = getResources().getString(R.string.hello, day , mon , yr);
TextView tx1 = (TextView)findViewById(R.id.text1);
tx1.setText(text);
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
List1 list = (List1)inflater.inflate(R.layout.list1, null);
list.setText(text);
ll.addView(list);
List1 list2 = (List1)inflater.inflate(R.layout.list1, null);
list2.setText(text);
ll.addView(list2);
}
}
主要的.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
android:id="@+id/mainlayout"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello" />
</LinearLayout>
list1.xml
<?xml version="1.0" encoding="utf-8"?>
<com.app.expensewatch.List1
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/list11"
android:background="@color/solid_red"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
/>