我希望你理解图像的问题。这个程序是关于listview的自定义适配器。
这是主要活动xml。
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.athis.practiceproject1.MainActivity">
<ListView
android:layout_width="match_parent"
android:layout_height="440dp"
android:id="@+id/listView"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:divider="#1affffff"
android:dividerHeight="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp">
</ListView>
<Button
android:id="@+id/filter_button"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:background="@drawable/filter"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginTop="5dp" />
<Button
android:id="@+id/sort_button"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_toLeftOf="@+id/filter_button"
android:layout_toStartOf="@+id/filter_button"
android:layout_marginRight="7dp"
android:layout_marginEnd="7dp"
android:layout_marginTop="5dp"
android:background="@drawable/sort"/>
<ImageButton
android:id="@+id/search_button"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginLeft="9dp"
android:layout_marginStart="9dp"
app:srcCompat="@android:drawable/ic_menu_search"
android:layout_alignTop="@+id/sort_button"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="14dp" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ems="8"
android:inputType="textPersonName"
android:hint="Search by Name"
android:layout_alignBaseline="@+id/sort_button"
android:layout_alignBottom="@+id/sort_button"
android:layout_toRightOf="@+id/search_button"
android:layout_toEndOf="@+id/search_button" />
</RelativeLayout>
这是主要活动代码
公共类MainActivity扩展了AppCompatActivity {
ListView mListView;
List<Project> projects = new ArrayList<>();
String[] mTitle = {"Robot Machine Project","Cold Coffee Maker","Game Creator"};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mListView = (ListView) findViewById(R.id.listView);
for(int i=0; i<=2; i++){
Project project = new Project();
project.setMtitle(mTitle[i]);
project.setmPleadges("Pleadge - $80000");
project.setmBackers("Backers - 1500");
project.setmNoDays("No. of Days to go - 21");
projects.add(project);
}
ProjectAdapter projectAdapter = new ProjectAdapter(MainActivity.this,projects);
mListView.setAdapter(projectAdapter);
mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent intent = new Intent(MainActivity.this,Main2Activity.class);
intent.putExtra("title",mTitle[position]);
intent.putExtra("pleadges","Pleadge - $80000");
intent.putExtra("backers","Backers - 1500");
intent.putExtra("days","No. of Days to go - 21");
startActivity(intent);
}
});
Button mFilterButton = (Button) findViewById(R.id.filter_button);
mFilterButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
PopupMenu popupMenu = new PopupMenu(MainActivity.this,v);
popupMenu.inflate(R.menu.filter_menu);
popupMenu.show();
}
});
}
}
答案 0 :(得分:3)
嗨问题在于您的布局:
我在列表标记
下的XML中添加了android:layout_below="@+id/filter_button"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.athis.practiceproject1.MainActivity">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="440dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="@+id/filter_button"
android:divider="#1affffff"
android:dividerHeight="10dp"
android:paddingLeft="10dp"
android:paddingRight="10dp"></ListView>
<Button
android:id="@+id/filter_button"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginEnd="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="5dp"
android:background="@drawable/filter" />
<Button
android:id="@+id/sort_button"
android:layout_width="60dp"
android:layout_height="60dp"
android:layout_alignParentTop="true"
android:layout_marginEnd="7dp"
android:layout_marginRight="7dp"
android:layout_marginTop="5dp"
android:layout_toLeftOf="@+id/filter_button"
android:layout_toStartOf="@+id/filter_button"
android:background="@drawable/sort" />
<ImageButton
android:id="@+id/search_button"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignTop="@+id/sort_button"
android:layout_marginLeft="9dp"
android:layout_marginStart="9dp"
android:layout_marginTop="14dp"
app:srcCompat="@android:drawable/ic_menu_search" />
<EditText
android:id="@+id/editText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="@+id/sort_button"
android:layout_alignBottom="@+id/sort_button"
android:layout_toEndOf="@+id/search_button"
android:layout_toRightOf="@+id/search_button"
android:ems="8"
android:hint="Search by Name"
android:inputType="textPersonName" />
</RelativeLayout>