这是我得到的错误: W/TextView: TextView does not support text selection. Selection cancelled.
我很惊讶,因为Textviews我之前已经实现过的其他RelativeLayout文件在我拥有该属性时可以选择文本android:textIsSelectable="true"- 但是,这次不起作用.
此代码放在app_bar_main.xml使用includeXML中的关键字下.
这是app_bar_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">
<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.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<include layout="@layout/content_main" /> //This is where the textview is added!
</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)
这是编辑过的content_main.xml:
<?xml version="1.0" encoding="utf-8"?>
<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:background="#ffffff"
android:orientation="vertical"
tools:context="com.androidterminal.MainActivity"
tools:showIn="@layout/app_bar_main">
//I have some other LinearLayouts …Run Code Online (Sandbox Code Playgroud) 我想知道为什么Android 开发人员文档建议使用视图组,例如Relative Layout或Linear Layout安排视图来开发 TV Android 应用程序,而不是当前的标准,即Constraint Layout。
有什么具体原因吗?我需要对此有一些想法。
android-linearlayout viewgroup android-relativelayout android-tv android-constraintlayout
当我设置我的时候CheckedTextView,它没有CheckBox.这是它的xml代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<CheckedTextView
android:id="@+id/checkedtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:checked="false"
android:textSize="25dp"
android:textColor="#FFFFFF"
android:checkMark="@android:attr/checkMark"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 在尝试为我想要的布局找到解决方案时,我遇到了setScaleX/setScaleY方法,它们是View类的成员.
现在看看RelativeLayout的方法和API Level 8的过滤,因为我正在开发一个> = 2.2的App,所以这些方法逐渐淡出.但是当查看" 从类android.view.View继承的XML属性 "时,属性android:scaleX/android:scaleY仍然可用.不幸的是,尝试使用这些属性并不起作用,Eclipse说:"错误:在'android'包中找不到属性'scaleX'的资源标识符"
所以看起来文档是矛盾的,scaleX/scaleY直到3.0才可用,或者我错过了什么?
我有一些ui小部件,包括RelativeLayout中的textview,可以点击.我的问题是,当relativelayout获得焦点时,textview文本颜色不会改变,尽管我已正确设置了textview颜色属性.
是否有任何简单的方法将焦点级联到相对布局内的子视图,与listview项目相同.
<RelativeLayout
android:id="@+id/top_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:background="@drawable/selector_white_blue"
>
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentLeft="true"
android:textSize="@dimen/text_size_med"
android:textColor="@color/black_text_white_focused"
android:textStyle="bold"
android:text="Movie Name"
/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) 所以,我有这个布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#FFFF00"
android:minHeight="100dp"
android:layout_gravity="bottom"
>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:textColor="#000000"
android:background="#FF0000"
android:text="Hello World"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_alignParentRight="true"
android:text="button"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
这就是它的样子:

但如果我android:layout_alignParentBottom="true"在这里添加按钮是它的样子:

我想将一个LinearLayout集中在RelativeLayout中,但我有一个问题,边缘底部保持附着在底部.这是观点:
http://nsa33.casimages.com/img/2013/03/12//130312103139937791.png
这是布局的代码:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/group_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/carreGlobalInterieur"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:background="@color/grisTresClair" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/border_deals"
android:orientation="vertical" >
<RelativeLayout
android:id="@+id/GroupLigneOne"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/grisClair"
android:orientation="vertical" >
<TextView
android:id="@+id/CategorieDeal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:text="My Category"
android:textColor="@color/white" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true" >
<TextView
android:id="@+id/nouveauPrixVert"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10.99 €"
android:textColor="@color/green"
android:textStyle="bold" />
<TextView
android:id="@+id/ancienPrixRouge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="7dp"
android:layout_marginRight="6dp"
android:text="20.90 €"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/red"
android:textSize="13sp"
android:textStyle="bold" />
<TextView
android:id="@+id/reductionPrix"
android:layout_width="wrap_content" …Run Code Online (Sandbox Code Playgroud) 好!过去几周我一直试图这样做,似乎无法找到一个很好的解决方案来实现我想要的.一直在尝试使用HorizontalScrollView,Gallery(不推荐使用).
我现在正在研究RecycleView,因为我遇到了这个方法.smoothScrollToPosition(),并认为这可能对我有帮助.
以下是我想要完成的事情的说明:

我还必须能够以编程方式创建相对布局
任何人都可以向我指出如何实现这一目标吗?有没有本土的方法呢?
编辑:在进一步了解@CommonsWare关于调查ViewPager的建议和来自Dave Smith的commonsware.com/blog/2012/08/20/第三篇文章后,我认为这是要走的路.还没有将它改为我的使用,但看起来不错.
我正在使用他的Github中的Dave Smiths样本:https://gist.github.com/devunwired/8cbe094bb7a783e37ad1
android horizontalscrollview android-scrollview swipe-gesture android-relativelayout
我正试图RelativeLayout在API 22上实现涟漪效应,但它没有显示出来.然而,同样的波纹起作用Button.
我的波纹drawable的代码如下:
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#d1c4e9">
<item android:id="@android:id/mask"
android:drawable="@android:color/white" />
<item android:drawable="@drawable/rect"/>
</ripple>
Run Code Online (Sandbox Code Playgroud)
相对布局代码如下:
<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"
tools:context=".MainActivity"
android:background="@drawable/ripple">
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
在此之后,波动被设定为在背景Button和RelativeLayout.按钮上的波纹效果很好,但根本没有出现RelativeLayout.
谁能告诉我我做错了什么?
在Android 6.0 Marshmallow上,EditText相对于RelativeLayout中的ImageView与属性baseline和layout_alignBaseline的定位不再起作用.甚至可以在Android studio的布局编辑器中观察到这种行为.在一个真正的Android Marshmallow设备或emulatr上,我的情况下EditText移出屏幕并且不可见.我是否会错过一些更改,这是一个错误吗?
<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:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context=".MainActivityFragment">
<ImageView
android:layout_width="48dp"
android:layout_height="48dp"
android:id="@+id/imageView"
android:src="@drawable/icon_category_geography_raster"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:baselineAlignBottom="true"
android:background="#00ffff"
/>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editText"
android:layout_alignParentTop="true"
android:layout_toRightOf="@id/imageView"
android:background="#ff0000"
android:inputType="text"
android:hint="Hint"
android:layout_alignBaseline="@id/imageView" />
Run Code Online (Sandbox Code Playgroud)
我创建了Android Studio布局编辑器的截图.这两个屏幕截图之间的区别仅在于API级别的更改.
我创建了一个示例项目 https://github.com/mikegr/baseline
android android-layout android-relativelayout android-6.0-marshmallow
android ×8
textview ×2
alignment ×1
android-tv ×1
android-view ×1
button ×1
colors ×1
viewgroup ×1