这是我第一次使用CoordinatorLayout,我真的不明白它是如何工作的.
我的LinearLayout与我的工具栏重叠,好像我在FrameLayout或RelativeLayout中,我不知道怎么告诉它在下面(像android:layout_below with RelativeLayout)
这是我的代码:
<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="192dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:src="@drawable/logo2"
app:layout_collapseMode="pin" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/appbar"
android:orientation="vertical"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
.... Very Large Form ...
</LinearLayout>
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
另一个疑问:我看到的几乎所有例子都是使用CoordinateLayout管理RecyclerView.我的布局不是RecyclerView,只是一个很长的形式.这样做是否有意义?
我在我的项目中使用Kotlin Android扩展,我遇到了一些我无法理解的行为.我使用此代码将我的片段保留在活动中:
val fragment = fragmentManager.findFragmentByTag("hello") ?: HelloFragment()
fragmentManager.beginTransaction()
.replace(R.id.fragment_container, fragment, "hello")
.commit()
Run Code Online (Sandbox Code Playgroud)
这是保留的Fragment:
import kotlinx.android.synthetic.hello.*
public class HelloFragment : Fragment() {
val text = "Hello world!"
override fun onCreate(savedInstanceState: Bundle?) {
super<Fragment>.onCreate(savedInstanceState)
setRetainInstance(true)
}
override fun onCreateView(inflater: LayoutInflater?, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater?.inflate(R.layout.hello, container, false)
}
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super<Fragment>.onViewCreated(view, savedInstanceState)
text_view.setText(text) // <- does not work when retained
}
}
Run Code Online (Sandbox Code Playgroud)
和它的XML布局hello.xml:
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text_view"
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) android android-layout android-fragments kotlin kotlin-android-extensions
嗨我有一个NavigationView,在NavigationView的headerview中有一个imageview.当我点击imageview时,NavigationView应该膨胀另一个菜单资源文件并替换PlayStore应用程序中的当前菜单.
我试过这个:
imgIndic.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Log.e("Onclick","Arrow click");
navigationView.inflateMenu(R.menu.second_menu);
}
});
Run Code Online (Sandbox Code Playgroud)
但是当我点击按钮时,没有任何反应!(Log onclick显示在logcat中)我该怎么做?
我创建了一个用Kotlin语言编写的Jar项目.Jar包含以下文件夹:
com
jet
kotlin
meta-inf
okio
org
Run Code Online (Sandbox Code Playgroud)
然后我创建了一个android项目并添加了Kotlin和Jar作为依赖项.
当我尝试执行hello world app时,会抛出异常.
com.android.ide.common.process.ProcessException: org.gradle.process.internal.ExecException: Process 'command '/usr/lib/jvm/java-7-openjdk-amd64/bin/java'' finished with non-zero exit value 1
我的app build gradle文件是
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
android {
compileSdkVersion 22
buildToolsVersion "22.0.1"
defaultConfig {
applicationId "abc.xyz.kotlin"
minSdkVersion 15
targetSdkVersion 22
versionCode 1
versionName "1.0"
}
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
sourceSets {
main.java.srcDirs += 'src/main/kotlin'
}
}
dependencies {
compile fileTree(include: ['*.jar'], dir: 'libs')
compile 'com.android.support:appcompat-v7:22.2.1'
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
compile …Run Code Online (Sandbox Code Playgroud) 我有一个Activity全屏显示.这与我尝试过的许多布局完美配合,除非CoordinatorLayout是根ViewGroup.它CoordinatorLayout本身的宽度和高度都设置为match_parent它,它需要整个屏幕.但是,子视图应该与CoordinatorLayout放置的大小相同,就像导航栏仍然可见一样.
有没有办法让孩子的视图调整大小CoordinatorLayout?显然fitSystemWindows不会改变一件事,因为这可能是由CoordinatorLayout实施引起的,其他ViewGroups工作也很好.我曾尝试创建自定义Behavior类,但我没有成功.
我用这段代码制作Activity全屏:
@Override
protected void onResume() {
super.onResume();
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
getWindow().getDecorView().setSystemUiVisibility(uiOptions);
}
Run Code Online (Sandbox Code Playgroud)
这是用于生成图像的简单布局:
<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:background="#F00">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
android:scaleType="centerCrop"
android:src="@drawable/background_sky_light" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud) android android-layout android-design-library android-coordinatorlayout
在我的应用程序中我使用内部CollapsingToolbarLayout跟随.我想要的是检测从中扫过,但是检测到并忽略滑动.这是我的XML:NestedScrollViewSwipeRefreshLayoutSwipeRefreshLayoutCollapsingToolbarLayoutNestedScrollViewCollapsingToolbarLayout
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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.support.design.widget.CoordinatorLayout
android:id="@+id/rootLayout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.widget.SwipeRefreshLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/swipe"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="256dp"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="@dimen/expanded_toolbar_title_margin_start"
app:layout_scrollFlags="scroll|exitUntilCollapsed">
<ImageView
android:id="@+id/profilePic"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:src="@drawable/ic_split_big_profile"
app:layout_collapseMode="parallax"
app:layout_collapseParallaxMultiplier="0.7" />
<include
android:id="@+id/toolbar_layout"
layout="@layout/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:layout_scrollFlags="scroll|enterAlways" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:id="@+id/transactions_scroll"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="500dp">
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
<android.support.design.widget.FloatingActionButton
android:id="@+id/add_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|right"
android:layout_marginBottom="@dimen/fab_margin_bottom"
android:layout_marginRight="@dimen/fab_margin_right"
android:onClick="addTxn"
android:src="@drawable/ic_action_add_transaction_light"
app:elevation="6dp"
app:fabSize="normal" /> …Run Code Online (Sandbox Code Playgroud) android android-layout swiperefreshlayout android-collapsingtoolbarlayout android-appbarlayout
我试图隐藏一个RelativeLayout使用setVisibility(View.GONE)。但这是行不通的。请检查我的代码:
<LinearLayout>
<RelativeLayout
android:id="@+id/AccelerometerView"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView />
<TextView />
<TextView />
<ImageView />
</RelativeLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
我正在使用以下代码来更改可见性:
private RelativeLayout tv;
tv = (RelativeLayout) findViewById(R.id.AccelerometerView);
tv.setVisibility(View.GONE);
Run Code Online (Sandbox Code Playgroud)
我的方法正确吗?我知道我们可以TextView单独隐藏这样的。但是我想在一个命令中同时隐藏所有三个TextView和全部ImageView。还有其他办法吗?
我开发了一个带有可扩展列表视图的导航抽屉,就像这样
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<fragment 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:id="@+id/map" tools:context=".HomeActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
<!-- The navigation drawer-->
<ExpandableListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"
android:listSelector = "@drawable/selector_list_item">
</ExpandableListView>
</android.support.v4.widget.DrawerLayout>
Run Code Online (Sandbox Code Playgroud)
我想SearchView在导航抽屉中添加一个,所以我将其添加到ExpandableListView
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<!-- The main content view -->
<fragment 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:id="@+id/map" tools:context=".HomeActivity"
android:name="com.google.android.gms.maps.SupportMapFragment" />
<!-- The navigation drawer-->
<ExpandableListView android:id="@+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="@android:color/transparent"
android:dividerHeight="0dp"
android:background="#111"
android:listSelector = "@drawable/selector_list_item">
<SearchView …Run Code Online (Sandbox Code Playgroud) 我想在笔记本靠近时在我的应用程序中禁用屏幕锁定器(即使它已锁定)或将其更改为一些简单的锁定,例如滑动解锁,这样我就不必每次都写入 12 位 PIN 码我想阅读通知的时间。
我知道如何检测同一网络中笔记本电脑的存在(它不安全,但通过默默无闻的安全性对我来说就足够了),但除了在非 root 设备上不可能找到之外,我找不到其他任何东西。有一个系统应用程序负责设置锁定屏幕,所以它一定是可能的。
我运行的是 Android 4.4。
我试图在另一个布局中使用新的Android Design Library的CoordinatorLayout.CoordinatorLayout包含RecyclerView.我试图做的是在CoordinatorLayout下面放置一个简单的LinearLayout.此布局应放在CoordinatorLayout下方.这是我使用的XML:
<LinearLayout 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"
android:fitsSystemWindows="true"
android:orientation="vertical">
<android.support.design.widget.CoordinatorLayout
android:layout_width="match_parent"
android:layout_height="fill_parent">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary" />
</android.support.design.widget.AppBarLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/conversation_recyclerview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scrollbars="vertical"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp"
android:orientation="horizontal">
<EditText
android:layout_width="fill_parent"
android:layout_height="match_parent" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@drawable/ic_send_white_36dp" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
如您所见,我试图将CoordinatorLayout包装在另一个LinearLayout中.但是,在屏幕上,布局的第二部分甚至无法渲染.