通常,活动将显示最大屏幕.我希望显示一个宽度为400px,高度为500px的窗口,但是下面仍然显示一个完整的窗口,为什么?
主要活动
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
}
}
Run Code Online (Sandbox Code Playgroud)
activity_main.xml中
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="400px"
android:layout_height="500px"
tools:context=".MainActivity">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World OK!"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
到克柳月
谢谢!但是你的代码不起作用,运行代码后窗口全屏显示.
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val m = windowManager
val d = m.defaultDisplay
val p = window.attributes
p.height = dp2px(this, 500f)
p.width = dp2px(this, 400f)
window.attributes = p
}
private fun dp2px(context: Context, …Run Code Online (Sandbox Code Playgroud) 我最近购买了一台连接到iOS和Android设备的蓝牙设备.
该设备使用经典蓝牙,在我的Android设备上看起来相当稳定,但是最近,我注意到我的iOS设备上的连接存在一些问题.它似乎偶尔变得有点不稳定.
在试图找出问题是否在我的最后时,我注意到蓝牙设备实际上总是可被发现.我做了一点挖掘,并且无法找到有关这种做法的更多信息.
我已经了解了蓝牙如何在2.4G频段上选择一个频道,以及80个频道中有3个用于发现.这是否意味着设备始终位于这3个通道中的1个,因为它始终可被发现?它是否也意味着它在嘈杂的频率下无法改变频道?
再说一次,我认为这在设置经典蓝牙连接方面是不好的做法,但我自己没有用蓝牙做太多工作,并且没有太多运气找到有关该问题的更多信息.在连接已经建立时,是否还会出现尝试连接的其他设备的问题?我相信一旦BLE设备建立连接就会隐藏起来,但我不认为这是经典蓝牙的情况.
以下观点必须是正方形.我也希望将视图限制在一定的大小.不知何故,当ConstraintLayout与同一元素上的dimensionRatio结合使用时,它忽略了max width/height属性.
<android.support.constraint.ConstraintLayout
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">
<View
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="@+id/guideline_top"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintLeft_toLeftOf="@+id/guideline_left"
app:layout_constraintRight_toRightOf="@+id/guideline_right"
app:layout_constraintBottom_toBottomOf="@+id/guideline_bottom"
app:layout_constraintWidth_max="100dp"
app:layout_constraintHeight_max="100dp"/>
Run Code Online (Sandbox Code Playgroud)
目前我通过将View放入容器中来使用解决方法,如下所示.但我宁愿保持我的布局层次尽可能平坦.
<android.support.constraint.ConstraintLayout
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.support.constraint.ConstraintLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="@+id/guideline_top"
app:layout_constraintLeft_toLeftOf="@+id/guideline_left"
app:layout_constraintRight_toRightOf="@+id/guideline_right"
app:layout_constraintBottom_toBottomOf="@+id/guideline_bottom"
app:layout_constraintWidth_max="100dp"
app:layout_constraintHeight_max="100dp">
<View
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintDimensionRatio="1:1"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
/>
Run Code Online (Sandbox Code Playgroud)
这是约束布局中的限制,您不能将最大宽度/高度与尺寸比结合使用吗?
我正在使用ConstraintLayout v1.0.2.
我是 ConstraintLayout 的新手。我试图设置 TextInputLayout 宽度以匹配父级,但它总是跳转到 365dp。而且我无法在另一个底部对齐 TextInputLayout。请帮我解决这个问题。 截屏
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayoutxmlns: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="dcastalia.com.cook4me.LoginActivity"
tools:layout_editor_absoluteY="81dp"
tools:layout_editor_absoluteX="0dp">
<android.support.design.widget.TextInputLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="39dp"
android:layout_marginLeft="32dp"
app:layout_constraintLeft_toLeftOf="parent"
android:layout_marginRight="32dp"
app:layout_constraintRight_toRightOf="parent"
android:layout_marginStart="32dp"
android:layout_marginEnd="32dp"
app:layout_constraintHorizontal_bias="0.0"
android:id="@+id/textInputLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hint" />
</android.support.design.widget.TextInputLayout>
<android.support.design.widget.TextInputLayout
android:layout_width="395dp"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
app:layout_constraintTop_toBottomOf="@+id/textInputLayout"
app:layout_constraintRight_toRightOf="@+id/textInputLayout">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:hint="hint" />
</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)
我在我的应用程序中使用了 RecyclerView,但是当我滚动我的 RecyclerView 时,我的项目将消失!我在很多 RecyclerView 中使用了这段代码,但这次我不知道发生了什么。有我的活动代码:
public class ActivityStartup extends AppCompatActivity {
Toolbar toolbar;
DrawerLayout drawerLayout;
NavigationView navigationView;
RecyclerView menuListRecycler;
RecyclerView schedualRecycler;
private List<ReminderModel> tempSchedualArray = new ArrayList<>();
/**
* ATTENTION: This was auto-generated to implement the App Indexing API.
* See https://g.co/AppIndexing/AndroidStudio for more information.
*/
private GoogleApiClient client;
LinearLayoutManager mSchedualLayoutManager = new LinearLayoutManager(ActivityStartup.this);
private FloatingActionButton mAddReminderButton;
RecyclerView.Adapter mSchedualAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
toolbar = (Toolbar) findViewById(R.id.toolBar);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
navigationView = (NavigationView) findViewById(R.id.navigationView); …Run Code Online (Sandbox Code Playgroud) 我已经阅读了很多关于 stackoverflow 的问题,但他们都没有回答这个问题。
我正在尝试设置动态链接,以便如果用户已经安装了应用程序,则链接会将用户深层链接到应用程序,如果没有,则链接到 Play 商店。我希望该链接在 Play 商店安装过程中继续存在,并通过链接发送到启动器活动。当应用程序已安装时,动态链接有效。但是,当应用程序未安装时,它会将用户发送到 Play 商店,但动态链接不会在安装过程中继续存在。我已经读过,当用户通过动态链接发送到 Play 商店时,“打开”按钮应该更改为“继续”,但是当我这样做时,它仍然显示“打开”。这是我在 AndroidManifest.xml 中的活动
<activity
android:name="com.xxx.xxx.xxx.xxx"
android:label="@string/app_name"
android:theme="@style/AppTheme.SplashScreen">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data
android:host="yyy.page.link"
android:scheme="http" />
<data
android:host="yyy.page.link"
android:scheme="https" />
</intent-filter>
</activity>
Run Code Online (Sandbox Code Playgroud)
活动如下:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_ia_login);
checkIfReferral();
}
private void checkIfReferral(){
FirebaseDynamicLinks.getInstance()
.getDynamicLink(getIntent())
.addOnSuccessListener(this, new OnSuccessListener<PendingDynamicLinkData>() {
@Override
public void onSuccess(PendingDynamicLinkData pendingDynamicLinkData) {
// Get deep link from result (may be …Run Code Online (Sandbox Code Playgroud) 我正在寻找 Android Html类支持的 HTML 标签和属性的简洁描述,特别是由Html#fromHtml()处理的那些标签。官方文档指出“并非所有 HTML 标签都受支持”,但这并没有多大帮助。我在网上找到的其他文档似乎已经过时,并且很少提及受支持的属性。
另外,我相信我应该使用HtmlCompat而不是Html,但我不清楚HtmlCompat的作用。文档指出HtmlCompat是“Html 的向后兼容版本”,但这是什么意思呢?当在 API 级别低于 24 的设备上运行时,我希望HtmlCompat#fromHtml()接受与Html在 API 24+ 设备上接受的标签相同的标签,但事实并非如此。
我用来<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />显示一个覆盖在其他应用程序上的弹出窗口,但 android 12 阻止了触摸。根据文档,它会阻止触摸事件,我如何允许在 android 12 上进行触摸。
这是 android 12 行为更改触摸事件的链接 https://developer.android.com/about/versions/12/behavior-changes-all#untrusted-touch-events
import android.app.Service;
import android.content.Intent;
import android.graphics.PixelFormat;
import android.hardware.input.InputManager;
import android.os.IBinder;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.WindowManager;
public class FloatWidgetService extends Service {
private WindowManager mWindowManager;
private View mFloatingWidget;
public FloatWidgetService() {
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
@Override
public void onCreate() {
super.onCreate();
final WindowManager.LayoutParams params;
mFloatingWidget = LayoutInflater.from(this).inflate(R.layout.layout_floating_widget, null);
mFloatingWidget.setFilterTouchesWhenObscured(true);
params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT, …Run Code Online (Sandbox Code Playgroud) 我有一个带图像的标题和带有一些项目的RecyclerView
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:id="@+id/header"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="100dp"
android:background="#ffffff">
<ImageView
android:layout_width="40dp"
android:layout_height="40dp"
android:padding="0dp"
android:id="@+id/imageView"
android:adjustViewBounds="true"
android:cropToPadding="false" />
</RelativeLayout>
<ProgressBar
android:id="@+id/progressBar1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true" />
<android.support.v7.widget.RecyclerView
android:id="@+id/recyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentStart="true"
android:scrollbars="vertical"
android:layout_alignParentLeft="true" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
RelativeLayout固定在RecyclerView之上.我想要的是滚动RecyclerView时滚动此标题(RelativeLayout).
有关如何使用RecyclerView滚动标题的任何想法?
我不确定它是否是ConstraintLayout的错误,所以我试着询问是否有人知道我犯了什么错误.
我有一个布局,我想在屏幕上均匀分布3个元素.如下所示:

我在它们之间形成了水平链条,正如你所看到的,它们均匀分布并且工作良好.
现在我想在每个元素中放置一个图像和一个TextView,如下所示:

所以这就是我尝试做的,以元素1为例:
<ImageView
android:id="@+id/image1"
android:layout_width="32dp"
android:layout_height="32dp"
android:src="@drawable/image1"
app:layout_constraintBottom_toBottomOf="@id/element_1"
app:layout_constraintLeft_toLeftOf="@id/element_1"
app:layout_constraintTop_toTopOf="@id/element_1"
app:layout_constraintRight_toLeftOf="@+id/text1"
app:layout_constraintHorizontal_chainStyle="packed"/>
<TextView
android:id="@+id/text1"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginLeft="2dp"
android:text="@string/text1"
app:layout_constraintBottom_toBottomOf="@id/element_1"
app:layout_constraintLeft_toRightOf="@id/image1"
app:layout_constraintRight_toRightOf="@id/element_1"
app:layout_constraintTop_toTopOf="@id/element_1"
app:layout_constraintHorizontal_chainStyle="packed"
android:gravity="center_vertical"/>
Run Code Online (Sandbox Code Playgroud)
可悲的是,它似乎"打破"了3个元素的链条.3个元素现在不会水平扩散,但包裹到非常小的尺寸:

如果我删除了ImageView和TextView之间的链,它可以正常工作.但后来我无法将ImageView和TextView置于元素中心.
有没有人遇到这样的事情?你是如何解决的?
现在,我知道我至少有两种方法可以解决这个问题:
(1)使用一个带有复合drawable的TextView,而不是ImageView + TextView;
(2)使用LinearLayout包装ImageView和TextView
但我想知道为什么它不起作用(这样我们可以更好地理解ConstraintLayout),而不是找到替代方案.
谢谢!
android android-layout android-constraintlayout constraint-layout-chains