我正在使用下面的布局,其中的CoordinatorLayout内部AppBarLayout(包含Toolbar和TabLayout内部)和占位符RelativeLayout,所以我可以在其上添加和替换片段.
我遇到了边距错误,我在RelativeLayout上添加的碎片将总是超出屏幕底部(与AppBarLayout高度大小相似的数量),我尝试将它的高度设置为wrap_content和match_parent,在这两种情况下它太过分了.
如果我app:layout_behavior="@string/appbar_scrolling_view_behavior"从RelativeLayout顶部移除它将在其下AppBarLayout也不是所希望的结果.
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/drawer_layout"
android:layout_height="match_parent"
android:layout_width="match_parent"
android:fitsSystemWindows="true">
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/main_content"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_scrollFlags="scroll|enterAlways" />
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
app:tabIndicatorHeight="4dp"
app:tabIndicatorColor="#ffffff"
app:tabMode="scrollable"
android:visibility="gone"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<RelativeLayout
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:id="@+id/main_fragment_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|bottom"
android:layout_margin="20dp"
android:src="@drawable/ic_done" />
</android.support.design.widget.CoordinatorLayout>
<android.support.design.widget.NavigationView
android:id="@+id/nav_view"
android:layout_height="match_parent"
android:layout_width="wrap_content"
android:layout_gravity="start" …Run Code Online (Sandbox Code Playgroud) android android-fragments android-design-library android-coordinatorlayout android-appbarlayout
我需要维护一个EditText可以由用户号码输入的内容,在某些情况下我需要将文本设置为EditText12 $.所以我需要能够setText()做任何我想要的事情.
我已经尝试设置一个EditText,输入类型设置为number,产生数字小键盘,同时删除InputFilterEditText的那个 - 这仍然不允许我放置非数字字符
input.setFilters(new InputFilter[] {});
Run Code Online (Sandbox Code Playgroud)
难道我做错了什么?有没有不同的方法来实现我的目标,一个带有数字小键盘的EditText,我可以编程方式插入一些非数字字符?
我试图获得DialogFragment运行时的宽度,我尝试了两种失败的方法.
第一:onCreateDialog创建对话框后的内部
public Dialog onCreateDialog(Bundle savedInstanceState) {
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity());
...
...
AlertDialog dialog = builder.create();
width = dialog.getWindow().getAttributes().width;
return dialog;
}
Run Code Online (Sandbox Code Playgroud)
width 设置为-1
第二:
public void onStart() {
width = getDialog().getWindow().getAttributes().width;
}
Run Code Online (Sandbox Code Playgroud)
width 设为-2
现在HorizontalScrollView.fullScroll(HorizontalScrollView.FOCUS_RIGHT)这让我烦恼了一段时间,我正在使用它向右滚动我的ScrollView,但不是所有的方式,它将滚动条向右移动99%,我可以手动滚动其余部分但由于某种原因它当我调用fullScroll()API 时不会这样做.
这是一个示例代码....如果您按下按钮几次,TextView将展开,您将看到问题.
活动:包com.example.test;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.HorizontalScrollView;
import android.widget.TextView;
public class MainActivity extends Activity {
TextView tv;
HorizontalScrollView hsv;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
tv = (TextView) findViewById(R.id.textView1);
hsv = (HorizontalScrollView)findViewById(R.id.horizontalScrollView1);
}
public void btnOnClick(View v) {
tv.append("a");
hsv.fullScroll(HorizontalScrollView.FOCUS_RIGHT);
}
}
Run Code Online (Sandbox Code Playgroud)
布局:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<HorizontalScrollView
android:id="@+id/horizontalScrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="push the button" />
</LinearLayout>
</HorizontalScrollView> …Run Code Online (Sandbox Code Playgroud)