我有一个textview,并希望它的角落呈圆形.我已经知道可以使用了android:background="@drawable/somefile".在我的情况下,此标记已包含在内,因此无法再次使用.例如android:background="@drawable/mydialogbox",已经在那里创建背景图像
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:layout_gravity="top"
android:background="@drawable/mydialogbox"
android:orientation="horizontal" >
<TextView
android:id="@+id/textview_name"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
所以当我textview(textview_name)还想要圆角时,如何实现这一目标.
考虑以下布局文件:
<?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"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.constraint.ConstraintLayout
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FF0000"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin">
<ImageView
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#0000FF"
android:padding="16dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintDimensionRatio="H,3:1"
tools:layout_editor_absoluteX="16dp" />
</android.support.constraint.ConstraintLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我不确定app:layout_constraintDimensionRatio是如何工作的.我的理解是比例总是宽度:高度.因此3:1将始终使ImageView看起来比高度宽3倍.前缀H或W告诉ConstraintLayout哪个维度应该尊重比率.如果是H则表示首先根据其他约束计算宽度,然后根据纵横比调整高度.然而,这是布局的结果:
高度是宽度的3倍,这是意料之外的.任何人都可以向我解释如何计算尺寸相对于app:layout_constraintDimensionRatio设置?
android scale aspect-ratio android-layout android-constraintlayout
我想按百分比设置边距.我在线性布局中有4个图像视图,并希望设置默认的左,右,上,下边距,每个屏幕尺寸保持相同的百分比.
可能吗 ?
这是一个我想要的演示..

这就是我尝试过但不起作用的东西
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:weightSum="10" >
<Thumbnail
android:id="@+id/thumb1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4" />
<Thumbnail
android:id="@+id/thumb2"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:weightSum="10" >
<Thumbnail
android:id="@+id/thumb3"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4" >
</Thumbnail>
<Thumbnail
android:id="@+id/thumb4"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4" />
</LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助
我正在寻找Pixel 2虚拟设备.我已经更新到最新的Android Studio RC2版本,但似乎Pixel设备是列表中的最后一个.
我知道我可以用Pixel 2分辨率创建自定义硬件配置文件,但Pixel 2显示器有圆角.
那么Pixel 2虚拟设备发布了吗?任何下载Pixel 2硬件配置文件的链接?
每当我构建,运行,清理,重建等时,我都在Android Studio项目上使用数据绑定库我收到以下错误:
:app:processDebugResources AGPBI:
{"kind":"error","text":"Error parsing XML: duplicate attribute","sources": [{"file":"C:\\Users\\lucia.beltran\\Desktop\\Picho\\Projects\\Personal\\ improved-tribble\\ImprovedTribble\\app\\build\\intermediates\\data-binding-layout-out\\debug\\ layout\\task_list_item.xml","position":{"startLine":16}}],"original":"","tool":"AAPT"}
C:\Users\lucia.beltran\Desktop\Picho\Projects\Personal\improved-tribble\ImprovedTribble\app\build\intermediates\data-binding-layout-out\debug\layout\task_list_item.xml:17: error: Error parsing XML: duplicate
FAILED
FAILURE: Build failed with an exception.
* What went wrong: Execution failed for task ':app:processDebugResources'.
> com.android.ide.common.process.ProcessException: Failed to execute aapt
* Try: Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output.
BUILD FAILED
Total time: 3.826 secs
Run Code Online (Sandbox Code Playgroud)
我的布局如下
<layout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<data>
<variable
name="task"
type="com.pichardo.improvedtribble.models.Task" />
</data>
<LinearLayout …Run Code Online (Sandbox Code Playgroud) 是否可以在CardView中使用ConstraintLayout以便为RecyclerView充气呢?
当前布局是这样的,但我想在CardView中显示它。
https://i.stack.imgur.com/MeArp.png
参考XML代码:
<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="wrap_content"
android:minHeight="?android:attr/listPreferredItemHeight"
android:background="@drawable/touch_selector"
android:paddingBottom="@dimen/list_item_padding_vertical"
android:paddingLeft="@dimen/list_item_padding_horizontal"
android:paddingRight="@dimen/list_item_padding_horizontal"
android:paddingTop="@dimen/list_item_padding_vertical">
<ImageView
android:id="@+id/weather_icon"
android:layout_width="@dimen/list_icon"
android:layout_height="@dimen/list_icon"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline"
tools:src="@drawable/art_clouds"/>
<TextView
android:id="@+id/date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/list_item_date_left_margin"
android:layout_marginStart="@dimen/list_item_date_start_margin"
android:textAppearance="@style/TextAppearance.AppCompat.Subhead"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintLeft_toRightOf="@+id/weather_icon"
tools:text="Today, April 03"/>
<TextView
android:id="@+id/weather_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
android:textColor="@color/secondary_text"
app:layout_constraintLeft_toLeftOf="@+id/date"
app:layout_constraintTop_toTopOf="@+id/guideline"
tools:text="Rainy"/>
<TextView
android:id="@+id/high_temperature"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="@dimen/forecast_temperature_space"
android:layout_marginRight="@dimen/forecast_temperature_space"
android:fontFamily="sans-serif-light"
android:textColor="@color/primary_text"
android:textSize="@dimen/forecast_text_size"
app:layout_constraintBottom_toTopOf="@+id/guideline"
app:layout_constraintRight_toLeftOf="@+id/low_temperature"
app:layout_constraintTop_toTopOf="@+id/guideline"
tools:text="19\u00b0"/>
<TextView
android:id="@+id/low_temperature"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:fontFamily="sans-serif-light"
android:gravity="end"
android:textSize="@dimen/forecast_text_size"
app:layout_constraintBottom_toBottomOf="@+id/guideline"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="@+id/guideline"
tools:text="10\u00b0"/>
<android.support.constraint.Guideline
android:id="@+id/guideline"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
app:layout_constraintGuide_percent="0.5"/>
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud) 我有一个 a 的RecyclerView内部,ConstraintLayout其顶部从a的底部开始textView,其底部向下延伸到父级。我希望此中的项目RecyclerView默认为RecyclerView. 我尝试添加gravity="bottom"并且还尝试了与foregroundGravity和相同的事情layout_gravity。我还尝试添加layout_gravity="bottom"到我的recyclerView项目的布局。尽管如此, 中的所有项目recyclerView仍然默认为顶部。我能做些什么来确保物品在底部吗?这是xml:
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/my_tv"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="needed to unlock next coupon"
android:textColor="@color/gray"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/irrelevant_tv"
android:layout_marginTop="@dimen/spacing_tiny"
android:gravity="center"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/rv"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginTop="@dimen/spacing_xl"
android:paddingTop="@dimen/spacing_large"
android:overScrollMode="always"
app:layoutManager="android.support.v7.widget.LinearLayoutManager"
app:layout_constraintTop_toBottomOf="@id/my_tv"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
我不想做wrap_content的recyclerView任何,因为否则就不是scrollable(我一直在这3项recyclerView,并根据用户的显示设置,recyclerView可以得到被推离屏幕,这需要我可以滚动)
android android-layout android-xml android-recyclerview android-constraintlayout
我想创建一个像Play商店一样的应用程序.所以有一个导航抽屉.当我们点击Store home Navigation Item或(启动应用程序后的第一个片段)时,有一个看似tablayout进入AppBarLayout.代码在Activity中看起来像这样
<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"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
当我们点击其中一个应用程序的应用程序详细信息片段视图中的应用程序似乎AppbarLayout中的CollapsingToolbarLayout.代码就像这样....
<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:fitsSystemWindows="true">
<android.support.design.widget.AppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="@dimen/detail_backdrop_height"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
android:fitsSystemWindows="true">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
android:fitsSystemWindows="true"
app:contentScrim="?attr/colorPrimary"
app:expandedTitleMarginStart="48dp"
app:expandedTitleMarginEnd="64dp">
<ImageView
android:id="@+id/backdrop"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:fitsSystemWindows="true"
app:layout_collapseMode="parallax" />
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:layout_collapseMode="pin" />
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent" …Run Code Online (Sandbox Code Playgroud) 我正在使用新Constraint布局来构建我的布局.我需要Button占用几乎整个屏幕宽度,这很容易使用约束.
正如您在图像中看到的那样,我将宽度设置为0dp(任意大小),但文本不会粘在中心,这通常是按钮文本的正常情况.
我尝试过: - 将重力设置为居中 - 将textAlignment设置为居中
看起来这个属性不能用于0dp宽度(任何大小).
所以我试图将宽度设置为match_parent使用重心.
它有点偏右.
有没有人知道如何解决这种行为?
请注意,我正在使用alpha4
compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha4'
XML代码
<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:id="@+id/content_login"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="br.com.marmotex.ui.LoginActivityFragment"
tools:showIn="@layout/activity_login">
<Button
android:text="Log in"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:id="@+id/btLogin"
android:layout_marginTop="48dp"
app:layout_constraintTop_toBottomOf="@+id/textView6"
android:layout_marginEnd="16dp"
app:layout_constraintRight_toRightOf="@+id/content_login"
android:layout_marginRight="16dp"
android:layout_marginStart="16dp"
app:layout_constraintLeft_toLeftOf="@+id/content_login"
android:layout_marginLeft="16dp"
android:textColor="@android:color/white"
android:background="@color/BackgroundColor" />
</android.support.constraint.ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
编辑这是ConstraintLayoutalpha4 中的一个错误.
更新谷歌发布了alpha5,上面的代码现在可以使用了. 发行公告
我在RecyclerView中有一个ViewHolder的XML布局.
此布局的根是ConstraintLayout,其高度设置为wrap_content.
在这个平面层次结构中,有3个文本视图和一个具有固定高度的图像视图; 考虑到:
<ConstraintLayout>
<TextView height=wrap>
<TextView height=wrap>
<TextView height=wrap>
<ImageView height=150dp>
</ConstraintLayout>
Run Code Online (Sandbox Code Playgroud)
这是一个相对简单的布局.在beta4这是它的外观在设计(并最终在运行时,每个recyclerView细胞):
为"繁文缛节"道歉,但它是NDA等等.
话虽这么说,要素是:
3个文本视图(红色录制带有漂亮的紫色背景)高度为150dp的ImageView是灰色的.
紫色背景应用于根ConstraintLayout.一切都好.
现在这就是它的外观,不需要对Beta 5进行任何修改:
正如您所看到的,紫色(根)约束布局现在"混淆",并且不会像过去那样包装内容.
我试过的事情:
添加app:layout_constraintHeight_default="wrap"到ConstraintLayout(并传播).没有什么区别.
ImageView有一个app:layout_constraintBottom_toBottomOf="parent"我试图删除的约束,也没有任何区别.
恢复到beta4 :)
为了记录,这是完整的布局(由于相同的原因,id已被重命名为出于繁文缛节的原因而没有工具:文本或类似的).布局在其他方面完全相同.
<?xml version="1.0" encoding="utf-8"?>
<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="wrap_content"
android:background="@color/colorAccent">
<TextView
android:id="@+id/toplabel"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:text=""
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="@+id/top_bottom_label"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toLeftOf="@+id/top_right_label"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/top_right_label"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="8dp"
android:ellipsize="end"
android:gravity="end"
android:maxLines="1"
android:text=""
app:layout_constraintBottom_toTopOf="@+id/top_bottom_label"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintLeft_toRightOf="@+id/toplabel"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_chainStyle="packed" />
<TextView
android:id="@+id/top_bottom_label"
android:layout_width="0dp"
android:layout_height="wrap_content" …Run Code Online (Sandbox Code Playgroud)