我需要上图中工具栏下方的空白处于滚动视图中。但添加滚动视图会产生this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar_newg"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:minHeight="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:layout_collapseMode="none"
app:elevation="0dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:theme="@style/ToolbarTheme"
app:popupTheme="@style/AppTheme.PopupOverlay">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingLeft="32dp"
android:paddingStart="32dp"
android:paddingBottom="40dp"
android:paddingRight="16dp"
android:paddingEnd="16dp">
<android.support.design.widget.TextInputLayout
android:id="@+id/entry_home_TIL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="0dp">
<android.support.design.widget.TextInputEditText
android:textSize="27sp"
android:ems="10"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textAutoComplete|textCapWords|textAutoCorrect"
android:id="@+id/entry_home" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/entry_away_TIL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="0dp">
<android.support.design.widget.TextInputEditText
android:textSize="27sp"
android:ems="10"
android:inputType="textAutoComplete|textCapWords|textAutoCorrect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/entry_away" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:id="@+id/entry_tourney_title_TIL"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:layout_marginBottom="0dp">
<EditText
android:hint="Tournament"
android:textSize="27sp"
android:ems="10"
android:inputType="textAutoComplete|textCapWords|textAutoCorrect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/entry_tourney_title" />
</android.support.design.widget.TextInputLayout>
</LinearLayout>
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/newGameFields"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#ffffff"
android:orientation="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:textColor="#000000"
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/ic_event_black_24dp"
android:drawableStart="@drawable/ic_event_black_24dp"
android:drawablePadding="31dp"
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:paddingBottom="15dp"
android:text="Time"
android:clickable="true"
android:id="@+id/dateText"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:textColor="#000000"
android:id="@+id/timeText"
android:textSize="16sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:drawableLeft="@drawable/ic_clock_black_24dp"
android:drawableStart="@drawable/ic_clock_black_24dp"
android:drawablePadding="31dp"
android:paddingTop="20dp"
android:paddingRight="30dp"
android:paddingStart="30dp"
android:paddingEnd="30dp"
android:clickable="true"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>
<View style="@style/Divider_Horz"/>
<EditText
android:hint="Location"
android:background="@null"
android:drawableLeft="@drawable/ic_place_black_24dp"
android:drawableStart="@drawable/ic_place_black_24dp"
android:drawablePadding="31dp"
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:paddingBottom="15dp"
android:inputType="textAutoComplete|textCapWords|textAutoCorrect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/entry_location" />
<View style="@style/Divider_Horz"/>
<EditText
android:hint="Add starters"
android:background="@null"
android:drawableLeft="@drawable/ic_people_black_24dp"
android:drawableStart="@drawable/ic_people_black_24dp"
android:drawablePadding="31dp"
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:paddingBottom="15dp"
android:inputType="textAutoComplete|textCapWords|textAutoCorrect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/entry_starters" />
<View style="@style/Divider_Horz"/>
<EditText
android:hint="Add note"
android:background="@null"
android:drawableLeft="@drawable/ic_short_text_black_24dp"
android:drawableStart="@drawable/ic_short_text_black_24dp"
android:drawablePadding="31dp"
android:paddingTop="20dp"
android:paddingLeft="20dp"
android:paddingStart="20dp"
android:paddingEnd="20dp"
android:paddingBottom="15dp"
android:inputType="textAutoComplete|textCapWords|textAutoCorrect"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/entry_notes" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
如果您在添加活动时曾使用Google日历应用,我希望它就像那样。
以下是相关的片段代码:
import android.app.DatePickerDialog;
import android.app.Dialog;
import android.app.TimePickerDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.net.Uri;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.TextInputLayout;
import android.support.v4.app.DialogFragment;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AlertDialog;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.text.format.DateFormat;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.inputmethod.InputMethodManager;
import android.widget.DatePicker;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.TimePicker;
import com.github.clans.fab.FloatingActionMenu;
import java.text.SimpleDateFormat;
import java.util.Calendar;
/**
* A simple {@link Fragment} subclass.
*/
public class NewGame extends Fragment {
//private static final String TAG = "AKDialogFragment";
EditText entryAway, entryHome;
private OnFragmentInteractionListener mListener;
private OnFragmentInteractionListener mListener2;
private static final int[] EDITTEXT_IDS = {
R.id.entry_home,
R.id.entry_away
};
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
FloatingActionMenu fab = (FloatingActionMenu) getActivity().findViewById(R.id.material_design_android_floating_action_menu);
fab.setVisibility(View.GONE);
setHasOptionsMenu(true);
View rootView = inflater.inflate(R.layout.fragment_new_game, container, false);
Toolbar toolbar = (Toolbar) rootView.findViewById(R.id.toolbar_newg);
toolbar.setTitle("");
((AppCompatActivity) getActivity()).setSupportActionBar(toolbar);
ActionBar actionBar = ((AppCompatActivity) getActivity()).getSupportActionBar();
if (actionBar != null) {
actionBar.setDisplayHomeAsUpEnabled(true);
actionBar.setHomeButtonEnabled(true);
actionBar.setHomeAsUpIndicator(R.drawable.ic_close_white_24px);
}
return rootView;
}
@Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
Calendar c = Calendar.getInstance();
int hour = c.get(Calendar.HOUR_OF_DAY);
int minute = c.get(Calendar.MINUTE);
final TimePickerDialog timePicker;
SimpleDateFormat sdf = new SimpleDateFormat("EEE, MMM d, yyyy");
String formattedDate = sdf.format(c.getTime());
((TextView) getActivity().findViewById(R.id.dateText)).setText(formattedDate);
setTime12Hour(hour,minute);
TextView textViewDate = (TextView) getActivity().findViewById(R.id.dateText);
textViewDate.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Do something in response to button click
DialogFragment picker = new DatePickerFragment();
picker.show(getFragmentManager(), "datePicker");
}
});
TextView textViewTime = (TextView) getActivity().findViewById(R.id.timeText);
textViewTime.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// Do something in response to button click
showTimePickerDialog(v);
}
});
String team = "West Albany";
EditText eTHome = (EditText) getActivity().findViewById(R.id.entry_home);
TextInputLayout eTHomeTil = (TextInputLayout) getActivity().findViewById(R.id.entry_home_TIL);
EditText eTAway = (EditText) getActivity().findViewById(R.id.entry_away);
TextInputLayout eTAwayTil = (TextInputLayout) getActivity().findViewById(R.id.entry_away_TIL);
switch (this.getTag()) {
case "home":
eTAwayTil.setHint("Away");
eTHome.setText(team);
break;
case "away":
eTHomeTil.setHint("Home");
eTAway.setText(team);
break;
case "tourney":
eTAwayTil.setHint("White");
eTHomeTil.setHint("Dark");
break;
case "scout":
eTHomeTil.setHint("Home");
eTAwayTil.setHint("Away");
break;
}
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
getActivity().getMenuInflater().inflate(R.menu.menu_ak, menu);
}
谢谢你们!
答案 0 :(得分:0)
尝试从AppBarLayout中删除android:fitsSystemWindows并添加到NestedScrollView marginTop AppBarLayout的高度(您可以在Fragment中计算此高度,例如尝试将marginTop设置为200dp)