这是你想要实现的吗?
Test Image http://imageshack.com/a/img43/3327/f091.png
如果是,那么描述就像,Item1 是微调器,底部的 Item 2 是 ListView,中间的黑线是 View,extire 布局是线性布局,它有一个孩子(滚动视图) 并且只有一个滚动视图的直接子视图是线性布局。
这是它的 xml。我不确定这是否是您要找的。p>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Spinner
android:id="@+id/spending_report_cycle_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/spending_report_graph"
android:layout_width="wrap_content"
android:layout_height="3dp"
android:layout_gravity="center_horizontal"
android:background="#000000"
android:orientation="vertical" />
<ListView
android:id="@+id/spending_report_listview"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
</ScrollView>
</LinearLayout>
这是编辑后的答案:
Test Image http://imageshack.com/a/img809/7741/ti70.png
这里我使用片段只是为了确认一切正常,是的,一切正常。
如您所见,这是我正在使用的片段,顶部是微调器,底部是列表视图,执行代码后,视图如下所示:
Test Image 2 http://imageshack.com/a/img713/685/qpbi.png
这里,两条绿线内的视图是片段。这是所有内容的代码:
首先:yourmainlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Spinner
android:id="@+id/spending_report_cycle_spinner"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/SomeView2"
android:layout_width="wrap_content"
android:layout_height="5dp"
android:layout_gravity="center_horizontal"
android:background="#008080"
android:orientation="vertical" />
<fragment
android:id="@+id/fragment_content_1"
android:name="com.mike.passintents.Fragment1"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<View
android:id="@+id/SomeView2"
android:layout_width="wrap_content"
android:layout_height="5dp"
android:layout_gravity="center_horizontal"
android:background="#008080"
android:orientation="vertical" />
<ListView
android:id="@+id/spending_report_listview"
android:layout_width="fill_parent"
android:layout_height="300dp"
android:background="#333333" >
</ListView>
</LinearLayout>
</ScrollView>
</LinearLayout>
第二个:片段1
import android.os.Bundle;
import android.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import com.mike.stackoverflowquestions.R;
public class Fragment1 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
return inflater.inflate(R.layout.fragment_fragment_1, container, false);
}
}
第三:主要活动
import java.util.ArrayList;
import android.app.Activity;
import android.os.Bundle;
import android.app.Fragment;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Spinner;
import android.widget.TextView;
import com.mike.stackoverflowquestions.R;
public class ActivityA extends Activity {
String somevalue1 = "Hello";
String somevalue2 = "World";
ListView mListView;
String[] numbers_text = new String[] { "one", "two", "three", "four",
"five", "six", "seven", "eight", "nine", "ten", "eleven", "twelve",
"thirteen", "fourteen", "fifteen" };
ArrayList<String> mArrayList;
ArrayAdapter<String> mAdapter;
ArrayAdapter<String> spinnerAdapter;
Spinner spinner1;
TextView tV;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.custom_view_stack);
mArrayList = new ArrayList<String>();
for (String s : numbers_text) {
mArrayList.add(s);
}
spinner1 = (Spinner) findViewById(R.id.spending_report_cycle_spinner);
tV = (TextView) findViewById(R.id.tv);
mListView = (ListView) findViewById(R.id.spending_report_listview);
mAdapter = new ArrayAdapter<String>(getApplicationContext(),
android.R.layout.simple_list_item_1, mArrayList);
mListView.setAdapter(mAdapter);
spinnerAdapter = new ArrayAdapter<String>(this, R.layout.spinner_item,
mArrayList);
spinner1.setAdapter(spinnerAdapter);
}
public void selectFragment(View view) {
Fragment fr;
if (view == findViewById(R.id.btnSayHi)) {
fr = new Fragment1();
} else {
fr = new Fragment1();
}
FragmentManager fm = getFragmentManager();
FragmentTransaction mFragmentTransaction = fm.beginTransaction();
mFragmentTransaction.replace(R.id.fragment_content_1, fr);
mFragmentTransaction.commit();
}
}
我进行了编辑。请让我知道这是否有效。祝你好运..:)