我正在尝试构建一个布局,其中屏幕顶部有一个文本视图,屏幕底部有一个底部栏.这些视图中的每一个都应保持固定,并且在2之间应该是ListView.
TOPBAR
LISTVIEW (scrollable)
BOTTOM BAR
Run Code Online (Sandbox Code Playgroud)
我的布局(见下文)几乎可以工作:顶部和底部组件保持固定,列表视图滚动."问题"是我的ListView的最后一行仍隐藏在底栏后面.
有关如何调整布局的任何建议?
谢谢!
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<LinearLayout
android:layout_alignParentTop="true"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:background="@drawable/blackgrad"
android:gravity="center"
android:id="@+id/title"
android:layout_height="50dip"
android:layout_width="fill_parent"
android:text="blah blah"
android:textColor="#ffffff"
android:textSize="18sp"
/>
<ListView
android:background="#ffffff"
android:cacheColorHint="#ffffffff"
android:id="@android:id/list"
android:layout_height="fill_parent"
android:layout_width="fill_parent"
/>
</LinearLayout>
<LinearLayout
android:background="#efefef"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_width="fill_parent"
android:layout_height="50dip"
android:orientation="horizontal">
<Button
android:layout_height="wrap_content"
android:id="@+id/back"
android:text="Back"
android:layout_width="wrap_content" />
<Button
android:layout_height="wrap_content"
android:id="@+id/home"
android:text="Home"
android:layout_width="wrap_content" />
<Button
android:layout_height="wrap_content"
android:id="@+id/next"
android:text="Next"
android:layout_width="wrap_content" />
</LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud) android footer android-layout android-linearlayout android-relativelayout
我有以下布局.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/list_item_bottom">
<TextView android:id="@+id/list_item_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
<ViewStub android:id="@+id/stub_for_alt_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/list_item_name"
android:layout="@layout/text_view_alt_name"/>
<ImageView android:id="@+id/list_item_dopinfo1_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/stub_for_alt_name"
android:src="@drawable/ic_released"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
我希望ViewStub低于TextView,ImageView低于ViewStub.
ViewStub膨胀的元素按照我的预期显示.但没有ViewStub的元素将TextView与ImageView重叠.
我的布局出了什么问题?
更新:
我发现的唯一解决方案是为ViewStub和相关的TextView提供相同的android:id值.
对不起我的英语不好.
我的工作基于https://github.com/harism/android_page_curl/
经过几个小时的研究,我找到了一些解决方案,但不是我在申请中遇到的所有问题.我在使用GLSurfaceView时遇到了一些麻烦.我有一个背景,有一个relativeLayout,一个GLSurfaceView和一个叠加在上面.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/background"
android:layout_width="match_parent"
android:background="@layout/backgroundrepeat"
android:layout_height="match_parent">
<com.m2y.foxprez.view.CurlView
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/openglview"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/overlay"
android:layout_width="match_parent"
android:layout_height="match_parent">
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
当我开始我的观点时:
setEGLConfigChooser(8,8,8,8,16,0);
setRenderer(renderer);
getHolder().setFormat(PixelFormat.TRANSLUCENT);
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
setZOrderMediaOverlay(true);
Run Code Online (Sandbox Code Playgroud)
在我的渲染器中:
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
gl.glClearColor(0f, 0f, 0f, 0f);
gl.glShadeModel(GL10.GL_SMOOTH);
gl.glHint(GL10.GL_PERSPECTIVE_CORRECTION_HINT, GL10.GL_NICEST);
gl.glHint(GL10.GL_LINE_SMOOTH_HINT, GL10.GL_NICEST);
gl.glHint(GL10.GL_POLYGON_SMOOTH_HINT, GL10.GL_NICEST);
gl.glEnable(GL10.GL_LINE_SMOOTH);
gl.glDisable(GL10.GL_DEPTH_TEST);
gl.glDisable(GL10.GL_CULL_FACE);
}
public synchronized void onDrawFrame(GL10 gl) {
gl.glClearColor(0f,0f,0f,0f);
gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
gl.glLoadIdentity();
}
Run Code Online (Sandbox Code Playgroud)
经过多次研究,我目前被阻止了这个结果:
使用setZOrderOnTop,我有背景,但叠加层在视图下.
使用setZOrderMediaOverlay,我有叠加层,但背景为黑色.
有人可以帮帮我吗?
我需要相对/线性布局的运行时尺寸.
activity_home.xml:
<RelativeLayout
android:id="@+id/rlParent"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
HomeActivity.java:
private int width, height;
RelativeLayout rlParent = (RelativeLayout) findViewById(R.id.rlParent);
w = rlParent.getWidth();
h = rlParent.getHeight();
Log.i("Width-Height", width+"-"+height);
Run Code Online (Sandbox Code Playgroud)
请分享你的想法.
我想保留imageView的纵横比,并调整它以尽可能大地填充/调整,而不会使用Picasso扭曲/改变它的纵横比.
到目前为止,我发现了这个:
建议使用:
.fit().centerInside()
Run Code Online (Sandbox Code Playgroud)
但是当我尝试时:
Picasso.with(this).load(boxart)
.fit().centerInside()
.into(imageItem);
Run Code Online (Sandbox Code Playgroud)
和我的XML一起:
<RelativeLayout
android:id="@+id/rl_ListView1"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_centerInParent="true"
android:layout_gravity="left"
android:layout_weight="0.3" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:scaleType="fitXY"
android:layout_gravity="left" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
然而,图像仍然显得扭曲(它看起来太长而且很瘦 - 它的原始宽高比是扭曲的)我不确定为什么.

我正在使用相对布局创建一个计算器屏幕,我有一排标记为1,2和3的按钮.我希望它们均匀分布,但我不知道如何使用相对布局
我习惯在LinearLayout中使用android:layout_weight函数,并给它们每个值一个android:layout_width ="fill_parent",以及layout_weight ="1"
任何方式在计算器屏幕上发生这种情况(不指定DP或PX)
这就是我现在设置的内容,它们在TextView(计算器输出屏幕)下按从左到右的顺序排列.任何建议/解决方案均匀空间,填充屏幕的宽度?
<TextView
android:id="@+id/textView"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/edit_text"
android:layout_margin="6px"
/>
<Button
android:id="@+id/button1"
android:text="1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
/>
<Button
android:id="@+id/button2"
android:text="2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_toRightOf="@+id/button1"/>
<Button
android:id="@+id/button3"
android:text="3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/textView"
android:layout_toRightOf="@+id/button2"
/>
Run Code Online (Sandbox Code Playgroud) 所以,我的问题是OnClickListener当我android:clickable="true"进入我的班级时不起作用.
这是MyClassxml代码:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="@drawable/background"
android:clickable="true">
...
...
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
MyClass.java:
public class MyClass extends RelativeLayout implements OnClickListener {
public MyClass(Context context) {
super(context);
LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
inflater.inflate(R.layout.book_item, this);
setOnClickListener(this);
}
public void onClick(View v) {
Log.v("TAG", "Hello");
}
...
...
}
Run Code Online (Sandbox Code Playgroud)
当我设置android:clickable为false 时,它工作正常.我错了什么?
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ListView
android:layout_above="@id/btn_4" <-- this line error: No resource found
android:layout_width="match_parent"
android:layout_height="200dp" />
<Button android:id="@+id/btn_4" <-- I declare the id here
android:layout_alignParentBottom="true"
android:layout_height="wrap_content"
android:layout_width="match_parent" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
有什么建议?
这是我得到的错误: 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