我想ImageView用in 重复图像RelativeLayout.它可以是可以使用位图xml和使用TILEMODE "repeat"用RelativeLayout,因为我已经看到了在互联网上都处理事情LinearLayout.
任何帮助或提示将受到热烈欢迎.
我试过两个对齐几个TextView对象,他们给了我相同的结果."基线"和"底部"之间究竟有什么区别?
我需要实现以下布局:

我在相对布局中有两个TextView:绿色的是固定文本wrap_content,黑色有动态文本wrap_content.黑色文本可以更改并变得非常长.我希望黑色TextView随文本一起展开,直到绿色视图到达父级的末尾.如果发生这种情况,黑色TextView应该停止扩展并椭圆化结束.
我怎样才能做到这一点?
我尝试了什么:
<RelativeLayout
android:id="@+id/parent"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="@+id/leftTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:maxLines="1"
android:layout_alignParentLeft="true"
android:textSize="18sp" />
<TextView
android:id="@+id/rightTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@id/leftTextView"
android:textSize="18sp" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
但是当黑色文本越来越大时,它会将绿色文本推出视图
我有一个RelativeLayout有两个孩子,也RelativeLayout包含几个按钮和东西.这些子布局不是在我的主布局中居中,主布局确实包含了这两个方面的一些其他东西.我希望第一个在第二个之上.这很容易,只需android:layout_below="@+id/firstLayout"在第二个使用.但我也希望第二个在第一个的中心对齐.我的意思是我想要第二个布局找到第一个布局的中心,并对齐自己,使其中心位于相同的x位置.我明白了alignLeft, alignRight, alignTop, and alignBaseline,但没有中心.是否可以这样做而不必硬编码边距来扫描第二个布局?
这是我想要最终得到的一个粗略的例子,蓝色条将是第一个布局,红色框将是第二个布局.我知道我可以将它们包装在另一个RelativeLayout大小相等的区域中"wrap_content",然后centerHorizontal="true"用于第二个区域.但我真的宁愿把两个都留作我的主要布局的孩子(如果我让他们成为一个单独布局的孩子,我将不得不对我的应用程序的某些部分的工作方式进行一些更改.我试图避免这种情况.)

简而言之,是否有可能告诉a中的孩子RelativeLayout始终匹配其高度,而RelativeLayout不管其他孩子的RelativeLayout行为如何?简而言之,就是这样.详情如下.
我想要实现的是一个ListView至少有三个视图的行,其中一个视图在列表条目的右侧是一种条带(下面的红色视图).我遇到的问题是TextView左侧有一个,并且根据我有多少文本,条纹不会填满整个布局.下面的图片非常清楚地解释了这一点.
ListView 项目布局:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<View
android:id="@+id/bottom_line"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_alignParentBottom="true"
android:background="#fc0" />
<!-- Why match_parent does not work in view below? -->
<View
android:id="@+id/stripe"
android:layout_width="80dp"
android:layout_height="wrap_content"
android:minHeight="50dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_alignParentBottom="true"
android:background="#f00" />
<TextView
android:id="@+id/text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_toLeftOf="@id/stripe"
android:text="This is a very long line, meant to completely break the match_parent property of the box at right"
style="?android:textAppearanceLarge"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
结果:

match_parent没有区别.我做的.重复这个问题,我希望红色条纹始终垂直填充父级.您可以看到条带未对齐到根的顶部.
注意:上面的例子是我能想到的最简单,最独立的例子.它只是一个由静态数组填充ListActivity …
我知道毕加索将图像加载到imageview等,但如何使用毕加索设置我的布局背景图像?
我的代码:
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.relativelayout);
relativeLayout.setBackgroundResource(R.drawable.table_background);
Picasso.with(MainActivity.this)
.load(R.drawable.table_background)
.resize(200, 200)
.into(relativeLayout);
return relativeLayout;
}
Run Code Online (Sandbox Code Playgroud)
我在这里给出了任何错误,说它无法解决.我有一个ScrollView和相对布局.
java android android-scrollview picasso android-relativelayout
我在我的片段中使用NestedScrollView.在我的xml里面的RelativeLayout但它没有覆盖整个屏幕高度.
以下是我的代码 -
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:fitsSystemWindows="true"
android:background="@color/black"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:background="@color/red_error_color"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
在运行代码时,只有黑色背景可见但不是红色,因为我的子视图背景为红色.
提前致谢
android android-scrollview android-relativelayout android-nestedscrollview
我见过一些人问过如何一次性缩放整个ViewGroup(例如RelativeLayout).目前,这是我需要实现的目标.对我来说,最明显的方法是将缩放比例因子保持为某个变量; 并且在每个子视图的onDraw()方法中,该比例因子将在绘制图形之前应用于Canvas.
然而,在这之前,我试图聪明(哈 - 通常是一个坏主意)并将RelativeLayout扩展到一个名为ZoomableRelativeLayout的类中.我的想法是,任何比例转换只能在重写的dispatchDraw()函数中应用于Canvas,因此绝对不需要在任何子视图中单独应用缩放.
这是我在ZoomableRelativeLayout中所做的.它只是RelativeLayout的一个简单扩展,其中dispatchDraw()被覆盖:
protected void dispatchDraw(Canvas canvas){
canvas.save(Canvas.MATRIX_SAVE_FLAG);
canvas.scale(mScaleFactor, mScaleFactor);
super.dispatchDraw(canvas);
canvas.restore();
}
Run Code Online (Sandbox Code Playgroud)
mScaleFactor由同一类中的ScaleListener操作.
它确实有效.我可以捏缩放ZoomableRelativeLayout,并将所有视图保持在一起正确重新缩放.
除了有问题.其中一些子视图是动画的,因此我会定期对它们调用invalidate().当比例为1时,可以看到这些子视图定期重绘完全正常.当比例不是1时,这些动画子视图只能在其观看区域的一部分中更新 - 或者根本不会更新 - 具体取决于缩放比例.
我最初的想法是,当一个人子视图的无效()被调用,那么它可能被单独由系统重新绘制,而不是传递从父的RelativeLayout的dispatchDraw()画布,这意味着子视图最终刷新自己没有应用缩放比例.但奇怪的是,在屏幕上重绘的子视图的元素是正确的缩放比例.这几乎就好像系统决定在后备位图中实际更新的区域仍然未缩放 - 如果这有意义的话.换一种方式,如果我有一个动画儿童观和我逐渐成为1的初始规模进一步和进一步放大,如果我们把一个假想的地方发现孩子的看法是该区域时,缩放比例为1 ,然后调用invalidate()只会导致刷新该虚构框中的图形.但是,这被视为更新显卡都正在做正确的规模.如果放大到目前为止,子视图现在已经完全远离它的比例为1,那么它的任何部分都不会被刷新.我将举一个例子:想象我的孩子视图是一个通过在黄色和红色之间切换来动画的球.如果我放大一点使得球向右和向下移动,在某一点你只会看到球的左上角四分之一的颜色.
如果我不断放大和缩小,我会看到孩子正确完整地观看动画.这是因为正在重绘整个ViewGroup.
我希望这是有道理的; 我试图尽我所能解释.使用我的可缩放ViewGroup策略,我有点失败吗?还有另外一种方法吗?
谢谢,
崔佛
android android-layout android-relativelayout android-viewgroup
我试图使我的按钮不完全在中心,但让我们说在屏幕高度的2/5s,我正在寻找属性失败,所以我试过这种方法
<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="@drawable/background"
android:padding="20dp" >
<ImageButton
android:id="@+id/flashlight_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_above="@+id/fakeView"
android:background="@null"
android:contentDescription="@string/flashlight_button_description"
android:src="@drawable/freeml_bright" />
<View
android:id="@+id/fakeView"
android:layout_width="10dp"
android:layout_height="10dp"
android:layout_centerInParent="true"
android:background="#FFAABB" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
但是它不起作用,即使我在假视图上设置了保证金.
有任何想法吗?
//编辑//
谢谢你的回答家伙,填充属性工作,但因为它是一个大图像,如果我希望它从屏幕高度的2/5开始,它覆盖屏幕的中心点,所以如果我使用填充属性它的工作,但它将它推离中心,不允许它覆盖它.对不起这是我的错
虽然,我使用线性布局工作,我想避免,因为在顶部和底部有更多的视图彼此相邻,所以它将导致使用线性布局的嵌套视图.不幸的是,我认为这是唯一的选择.
它基本上使用另一个线性布局,填充顶部和底部视图未使用的剩余空间,高度= 0dp,权重= 1,并将其重力设置为中心
<?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"
android:padding="20dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="@string/application_logo_description"
android:src="@drawable/mylight" />
<ImageButton
android:id="@+id/settings_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:background="@null"
android:contentDescription="@string/settings_button_description"
android:src="@drawable/settings_button" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="@+id/flashlight_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@null"
android:contentDescription="@string/flashlight_button_description" …Run Code Online (Sandbox Code Playgroud) android center android-layout android-view android-relativelayout
我尝试以编程方式更改布局高度.我有两个按钮.在一个按钮中我改变了我的布局位置和第二个按钮我尝试接收保存位置,这是我第一次.
<RelativeLayout
android:id="@+id/popaplayout"
android:layout_width="fill_parent"
android:layout_height="200dp" >
Run Code Online (Sandbox Code Playgroud)
这是我的布局和我写的第一个按钮
RelativeLayout.LayoutParams parms = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.FILL_PARENT);
parms.addRule(RelativeLayout.BELOW, R.id.movies_title_layout);
scrollpopap.setLayoutParams(parms);
scrollpopap.setScrollingEnabled(true);
Run Code Online (Sandbox Code Playgroud)
和第二个按钮
RelativeLayout.LayoutParams rel_btn = new RelativeLayout.LayoutParams(
ViewGroup.LayoutParams.WRAP_CONTENT, 300);
rel_btn.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM);
scrollpopap.setLayoutParams(rel_btn);
scrollpopap.setScrollingEnabled(false);
Run Code Online (Sandbox Code Playgroud)
在xml文件中我写了高度200dp和编程300,并有不同的高度.我怎样才能以编程方式编写保存高度?
如果有人知道解决方案,请帮助我谢谢