我有一个相对布局填满整个屏幕.我想在它的中间添加一个scrollview来包装一堆内容,这样我就可以在显示软键盘时使其平移.但是,只要我将其包装在滚动视图中,最底部的布局就会停止填充屏幕的其余部分.
这是我ScrollView注释掉的XML .
<include
android:id="@+id/top_bar_with_save_button"
layout="@layout/top_bar_with_save_button"/>
<FrameLayout
android:id="@+id/log_entry_title_frame"
android:layout_below="@id/top_bar_with_save_button"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@id/log_entry_title_frame"
android:layout_alignParentBottom="true">
<!--
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="@+id/log_entry_title_frame"
android:orientation="vertical"
android:background="#f00">
<!-- Lots of stuff in here -->
<EditText
android:id="@+id/log_entry_notes"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="8dp"
android:gravity="top|left"/>
</RelativeLayout>
<!--
</ScrollView>
-->
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
它看起来像这样:
但是一旦我删除它的评论ScrollView立即压缩如下:
为什么会这样?我需要它来填充屏幕上的整个空间,我无法弄清楚发生了什么.谁能告诉我如何解决这个问题?谢谢!
我在我的活动XML布局中实现了一个进度条,但是当我尝试在我的活动类中强制转换它时,我收到以下错误.
不可转换的类型; 无法投射android.view.View com.project.Progress栏
我已经研究过这个错误,但我仍然不确定如何解决它.
public class ProgressBar extends Activity{
ProgressBar progressbar;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_progress_bar);
progressbar = (ProgressBar) findViewById(R.id.progressBar);
}
}
Run Code Online (Sandbox Code Playgroud)
activity_progress_bar.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res /android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<ProgressBar
android:id="@+id/progressBar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="91dp"
android:minHeight="60dp"
android:minWidth="220dp" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 所以我正在尝试在Android Studio中构建一个登录应用程序,当我测试它时,应用程序因某些原因崩溃了.我只是在查看日志以找出问题,但我不能为此异常错误做到这一点.贴在下面是我的日志.
02-09 16:18:09.482 2467-2467/? I/art: Not late-enabling -Xcheck:jni (already on)
02-09 16:18:09.585 2467-2467/edu.dtcc.bwharto9.loginform W/System: ClassLoader referenced unknown path: /data/app/edu.dtcc.bwharto9.loginform-2/lib/x86
02-09 16:18:09.590 2467-2467/edu.dtcc.bwharto9.loginform D/AndroidRuntime: Shutting down VM
02-09 16:18:09.590 2467-2467/edu.dtcc.bwharto9.loginform E/AndroidRuntime: FATAL EXCEPTION: main
Process: edu.dtcc.bwharto9.loginform, PID: 2467
java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{edu.dtcc.bwharto9.loginform/edu.dtcc.bwharto9.loginform.MainActivity}:
java.lang.NullPointerException: Attempt to invoke virtual method 'android.view.View android.view.Window.findViewById(int)' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2327)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2476)
at android.app.ActivityThread.-wrap11(ActivityThread.java)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1344)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:148)
at android.app.ActivityThread.main(ActivityThread.java:5417)
at java.lang.reflect.Method.invoke(Native Method)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
Caused by: …Run Code Online (Sandbox Code Playgroud) 我构建会提到,支持多种设备尺寸的应用在这里.
为了处理意见里面的Fragment一个可能要么做查找与findViewById在活动的onCreate()或片段的onViewCreated().
他们都会工作,因为:如果你从Activity你那里做到这一点,你将处理Fragment父母的,你的View意志仍然在其中,如果你从中做到Fragment这将有正常的findViewById行为.
所以...
他们都有自己的优势:
如果你这样做Activity:
如果你这样做Fragment:
有这个问题的方式.在他们讨论有关使用getView或getActivity调用findViewById的Fragment.
接受的答案是:
而不是使用getActivity().findViewById(),你需要getView().findViewById().这样做的原因是,如果您使用活动进行视图查找,那么当具有相同视图ID的多个片段附加到该视图时,您将遇到麻烦
但是,如果你永远不会Fragment在相同的布局中重复使用,那么在查找中这是一个很好的情况Activity吗?
示例布局:
main_activity.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".MainActivity">
<fragment
android:id="@+id/f_main"
class=".fragments.MainFragment"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:layout="@layout/fragment_main" /> …Run Code Online (Sandbox Code Playgroud) 我知道可以通过活动转换来在活动A和活动B之间对共享元素进行转换,如下所示:
ActivityOptions options = ActivityOptions.makeSceneTransitionAnimation(this,
Pair.create(view1, "agreedName1"),
Pair.create(view2, "agreedName2"));
Run Code Online (Sandbox Code Playgroud)
同一活动中的片段也有片段转换。但是,是否有一种方法可以在活动A的“片段”视图和活动B之间转换共享元素?
我的活动A有一个带有片段的ViewPager,这些片段具有要转换为活动B的视图的视图。因此,我要转换为活动B的视图实际上是在活动A的“片段”布局中,而不是直接在活动A的布局中。
有什么办法可以使这项工作吗?
android android-layout android-transitions activity-transition
我的活动中有以下布局:
CoordinatorLayout
?? AppBarLayout
? ?? CollapsibleToolbarLayout
? ?? TextView (parallax)
? ?? TextView (pin)
? ?? Toolbar
?? NestedScrollView
?? LinearLayout
?? TextView 1
?? LinearLayout 1
? ?? 1 to n Views (dynamically added/removed)
...
?? TextView n
?? LinearLayout n
?? 1 to n Views (dynamically added/removed)
当我将Layouts中的animateLayoutChanges设置为true时,无论何时在NestedScrollView内部发生布局更改,结果布局都会与AppBarLayout的内容重叠.
我尝试了这个stackoverflow评论中的建议,但它没有帮助.
有没有人有类似/相同的问题,并找到了解决方案?
android android-animation android-layout android-collapsingtoolbarlayout android-appbarlayout
据我所知,Android中的Layouts我只是想问下面的陈述是否真实?
是否可以使用LinearLayout对Android中的每个RelativeLayout进行编程?
我个人认为每个RelativeLayout也可以使用LinearLayout完成.那么为什么有人会使用RelativeLayout而不是Linear呢?
谢谢
那
我试过实现它.
mProgressDialog = new ProgressDialog(this);
mProgressDialog.getWindow().setContentView(R.layout.footcloth);
mProgressDialog.setMessage(Constants.PROGRESS_DIALOG_MESSAGE);
mProgressDialog.show();
Run Code Online (Sandbox Code Playgroud)
但是这个代码抛出异常
java.lang.RuntimeException: Unable to start activity ComponentInfo{im.anticafe.anticafeim/im.anticafe.anticafeim.activities.HomeActivity}: android.util.AndroidRuntimeException: requestFeature() must be called before adding content
Run Code Online (Sandbox Code Playgroud)
此代码在活动BottomBarActivity中实现
abstract public class BottomBarActivity extends AppCompatActivity implements View.OnClickListener {
private static final String TAG = "bottomBarActivity";
private int mWidth;
private ProgressDialog mProgressDialog;
@Override
protected void onCreate(Bundle savedInstanceState) {
...
mProgressDialog = new ProgressDialog(this);
mProgressDialog.getWindow().setContentView(R.layout.footcloth);
mProgressDialog.setMessage(Constants.PROGRESS_DIALOG_MESSAGE);
mProgressDialog.show();
...
}
...
}
Run Code Online (Sandbox Code Playgroud)
而这项活动正在其他方面扩展.所以,请帮我解决我的问题,谢谢)
我的闹钟设计布局listView如下图所示.
custom_row_view
<?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">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingTop="10dp">
<TextView
android:id="@+id/time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="30sp"
android:text="Time"
android:paddingLeft="40dp"
android:paddingTop="15dp"
android:textColor="@color/black"
android:textStyle="bold"
/>
<ToggleButton
android:id="@+id/switchAlarm"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textOff=""
android:textOn=""
android:layout_marginLeft="200dp"
android:drawableTop="@mipmap/switch_alarm"
/>
</RelativeLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="10dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Text"
android:id="@+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Text"
android:layout_marginRight="@+id/textView"
android:id="@+id/textView1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Text"
android:layout_marginRight="@+id/textView1"
android:id="@+id/textView2" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Text"
android:layout_marginRight="@+id/textView2"
android:id="@+id/textView3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="5dp"
android:textAppearance="?android:attr/textAppearanceSmall" …Run Code Online (Sandbox Code Playgroud) android ×10
android-layout ×10
android-collapsingtoolbarlayout ×1
java ×1
progress-bar ×1
xml ×1