我正在尝试创建一个应用程序,该应用程序将具有一组相似的屏幕,因为它们在顶部有一个布局,在底部有一组按钮。基本上发生的情况是,底部的一个按钮是一个微调器,并且选择的每个选项都应将布局扩展到屏幕的上半部分,同时将所有按钮保留在底部。
解决这个问题的最佳方法是什么,而无需重写屏幕底部按钮的 xml 部分。
从上图中,我需要底部的五个按钮在所有屏幕上保持相同,而当从微调器中选择其中一个选项时,需要更改其上方的所有内容。
我的代码目前如下:它目前将按钮放在底部,并将文本放在红色框中,该文本将出现在每个屏幕上。我需要做的是将个人布局膨胀到两者之间的空间中。 setContentView(R.layout.people1);
if (v.getId() == R.id.service_user_button)
{
Spinner spinner = (Spinner) findViewById(R.id.people_spinner);
ArrayAdapter<CharSequence> adapter = ArrayAdapter.createFromResource(
getBaseContext(), R.array.service_user_array, android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner.setAdapter(adapter);
}
最佳答案
您希望布局看起来像这样:
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1"
>
<LinearLayout
android:id="@+id/theContent"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</ScrollView>
<!-- Buttons go inside this -->
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
</LinearLayout>
在运行时,您使用 id 'theContent' 查找 LinearLayout 并将其子级分配给它。
关于android - Android 屏幕上的两种布局,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9361957/