对于Android,LinearLayout布局不带边框属性。但是,您可以将LinearLayout的背景设置为9补丁图像。
只要将其链接回您的Java文件,您就可以修改您创建的xml文件上的任何内容。
例子: 如果您的XML文件是:
xmlns:android="http://schemas.android.com/apk/res/android"`
android:id="@+id/linearlayout"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
然后在你的Java文件,你不得不这样做:如果你
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.whateverXMLFile);
//get the Linear Layout you're searching for
LinearLayout linLayout = (LinearLayout) findViewById(R.id.linearlayout);
/*background is your background image you want to replace with.
* You can use any that is in your drawable resource.
* Better to use a 9 sketch because it'll expand to fit your width/height, no matter
* how big or small your layout will be.
*/
linLayout.setBackgroundResource(R.drawable.background);
//if you want to set the background colour:
//will set it to RED, you can also specify a resource file you may have for it
linLayout.setBackground(Colour.RED);
}