我想创建适合整个屏幕宽度的控制条,所以我使用了以下代码:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:background="#d9dee1"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@drawable/buttonsborder"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:orientation="horizontal"
>
<Button
android:id="@+id/Chemo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Chemo"
android:background="@drawable/firstbuttoncolorstyle"
android:textColor="@drawable/firstbuttontextstyle"
/>
<Button
android:id="@+id/inpatient"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="inpatient"
android:background="@drawable/firstbuttoncolorstyle"
android:textColor="@drawable/firstbuttontextstyle"
/>
<Button
android:id="@+id/Mgmt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Mgmt"
android:background="@drawable/firstbuttoncolorstyle"
android:textColor="@drawable/firstbuttontextstyle"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/PFinder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="PFinder"
android:background="@drawable/secondbuttoncolorstyle"
android:textColor="@drawable/secondbuttontextstyle"
/>
<Button
android:id="@+id/Afinder"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Afinder"
android:background="@drawable/secondbuttoncolorstyle"
android:textColor="@drawable/secondbuttontextstyle"
/>
<Button
android:id="@+id/Calender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Calender"
android:background="@drawable/secondbuttoncolorstyle"
android:textColor="@drawable/secondbuttontextstyle"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<Button
android:id="@+id/Profile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Profile"
android:background="@drawable/thirdbuttoncolorstyle"
android:textColor="@drawable/secondbuttontextstyle"
/>
<Button
android:id="@+id/SODEOD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="SOD/EOD"
android:background="@drawable/thirdbuttoncolorstyle"
android:textColor="@drawable/secondbuttontextstyle"
/>
<Button
android:id="@+id/Clear"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Clear"
android:background="@drawable/thirdbuttoncolorstyle"
android:textColor="@drawable/secondbuttontextstyle"
/>
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<ImageButton
android:id="@+id/maillme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/mail" />
<ImageButton
android:id="@+id/callme"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/call" />
</LinearLayout>
</LinearLayout>
<!-- the two columns part -->
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="0.80"
android:orientation="horizontal"
>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight=".80"
android:id="@+id/submenue"
>
<!-- this will be the menue list -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First Name" />
</LinearLayout>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight=".20"
android:id="@+id/mainLayout"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="second Name" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
但结果如下图
如何通过屏幕宽度(颜色按钮)传播控件,以及我使用此代码在按钮单击的运行时创建的列表
this.inpatient = (Button)this.findViewById(R.id.inpatient);
this.inpatient.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
String[] MainMenue = new String[] { "Chemo Unit", "Inpatient", "Patient tests","Management", "Instructions","Profile","Tools"};
// remove all controls
LinearLayout formLayout = (LinearLayout)findViewById(R.id.submenue);
formLayout.removeAllViews();
menueview = new ListView(getApplicationContext());
menueview.setVisibility(ListView.VISIBLE);
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(
LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params.gravity = Gravity.RIGHT;
menueview.setLayoutParams(params);
menueview.setAdapter(new submenueadapter(menueview.getContext(), MainMenue));
formLayout.addView(menueview);
}
});
如何增加字体和填充高度