相关疑难解决方法(0)

fill_parent和wrap_content有什么区别?

在Android中,布局小部件时,fill_parent(match_parent在API级别8和更高级别)和wrap_content?之间有什么区别?

你有什么文件可以指出吗?我很有兴趣了解它.

layout user-interface android

271
推荐指数
3
解决办法
26万
查看次数

layout_gravity无法在水平线性布局中工作

我一直试图layout_gravity在横向使用linear layout.但它似乎没有用.我希望使用relative layout或任何其他布局.我想知道为什么它不与工作linear layout.我刚才使用layout_gravityvertical线性布局,它在我的预期的方式工作过.

<LinearLayout
    android:id="@+id/shata"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    >
    <TextView
        android:id="@+id/title_textview"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:textColor="@color/black"
        android:text="shata1"
        android:textAppearance="?android:attr/textAppearanceMedium"
        />
    <TextView
        android:id="@+id/map_imageview"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:text="shata2"/>    
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

正如您所看到的,线性布局有一个orientation=horizontalwidth=match_parent(它只是在根布局内).但是,LinearLayout尽管我已经分别给出了它们layout_gravity=center,但两个TextView都显示在左侧layout_gravity=right.

android android-linearlayout

21
推荐指数
2
解决办法
2万
查看次数

RelativeLayout重量

在布局资源XML中,我有3个RelativeLayout(s),它们位于主RelativeLayout中.视图将垂直显示.这三个RelativeLayout()彼此相邻设置,我想让它们填满整个屏幕,无论屏幕大小是多少.我的布局视图:

<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/backg"
 >

<ImageView
    android:id="@+id/imageView1"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true"
    android:layout_marginTop="@dimen/top_mr_image"
    android:src="@drawable/temp" />

<RelativeLayout
    android:id="@+id/r1"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentLeft="true"
    android:layout_below="@+id/imageView1"
    android:layout_marginLeft="10dp"
    android:background="@drawable/r1bg"
    android:layout_weight="1"

     >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_marginLeft="@dimen/txt_mr_right"
        android:layout_marginRight="@dimen/txt_mr_right"
        android:layout_marginTop="39dp"
        android:text="S"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_below="@id/textView1"
        android:layout_marginLeft="@dimen/txt_mr_right"
        android:layout_marginRight="@dimen/txt_mr_right"
        android:text="T"
        android:textAppearance="?android:attr/textAppearanceLarge" />
</RelativeLayout>

    <RelativeLayout
        android:id="@+id/r2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignTop="@+id/r1"
        android:layout_toRightOf="@+id/r1"
        android:layout_weight="1" >
    </RelativeLayout>

            <RelativeLayout
        android:id="@+id/r3"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_alignTop="@+id/r2"
        android:layout_toRightOf="@+id/r2"
        android:layout_weight="1" >

    </RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

我设置weight=1layout_width=0dp为每个relativeLayout和这个技术使用按钮,我认为相同的将是relativeLayout,似乎我的想法是错误的.任何的想法?

UPD1:我添加了一张我想要的图像

在此输入图像描述

android android-layout

20
推荐指数
2
解决办法
7万
查看次数

隐形部件仍占用空间

所以,我有一个看起来像这样的活动:

http://i.imgur.com/UzexgEA.jpg

如您所见,它有一个按钮,一个列表和一个按钮.

如果满足某些条件,我想隐藏两个按钮只显示列表,但正如您在下一个图像中看到的那样,按钮仍占用空间:

http://i.imgur.com/OyLIfSk.jpg

所以我的问题是,我可以做些什么来扩大列表以占用空间?

这是按钮和列表的布局:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical" >

    <Button
        android:id="@+id/findSelected"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="registrarAsistencia"
        android:text="Registrar Asistencia" />

    <ListView
        android:id="@+id/listaAlumnos"
        android:layout_width="fill_parent"
        android:layout_height="376dp"
        android:layout_weight="2.29" />

    <Button
        android:id="@+id/btnChecarBoxes"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:onClick="seleccionarTodosNinguno"
        android:text="Seleccionar / Deseleccionar todo" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这里是列表内容的布局:

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

  <LinearLayout
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:layout_alignParentLeft="true"
      android:layout_alignParentTop="true"
      android:orientation="vertical" >

      <TextView
          android:id="@+id/rowTextView"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:padding="10dp"
          android:textSize="16sp" 
          android:textStyle="bold"/>

      <TextView
          android:id="@+id/rowTextView2"
          android:layout_width="wrap_content"
          android:layout_height="match_parent"
          android:padding="10dp"
          android:textSize="16sp" 
          android:textStyle="italic"/>

  </LinearLayout>

  <CheckBox
      android:id="@+id/CheckBox01"
      android:layout_width="wrap_content"
      android:layout_height="match_parent"
      android:layout_alignParentRight="true"
      android:layout_centerVertical="true"
      android:focusable="false" …
Run Code Online (Sandbox Code Playgroud)

android android-layout

18
推荐指数
1
解决办法
1万
查看次数

TextView在某些分辨率下被削减

我有一个RecyclerView包含CardViews TextView和a ImageView,以及其他一些布局的s .
问题是,在某些屏幕分辨率TextView下,它会被切断或推到下一行,这是我不想要的.
在其他决议中,TextView有足够的空间.

小决议:
小

高分辨率:
在此输入图像描述

如何组织布局,以便有足够的空间TextView,并相应ImageView地调整大小?

这是我的RecyclerView项目的xml :

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
android:id="@+id/zmanCard"
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="center_horizontal"
android:gravity="center_horizontal"
cardview:cardUseCompatPadding="false"
cardview:cardPreventCornerOverlap="false"
cardview:cardCornerRadius="4dp"
cardview:cardElevation="2dp">
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/colorPrimary"
    android:orientation="vertical">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="20dp"
        android:layout_gravity="top"
        android:gravity="center"
        android:orientation="vertical"
        android:background="?attr/colorPrimaryDark">
        <TextView
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/zmanCardTitle"
            android:textColor="#ffffff"
            android:gravity="center"
            android:textSize="13sp" />
    </LinearLayout>
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal">
        <ImageView
            android:layout_width="24dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="2dp"
            android:layout_marginLeft="2dp"
            android:layout_marginRight="4dp"
            android:alpha="0.8"
            android:id="@+id/zmanCardImage" />
        <FrameLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="7dp"
            android:layout_marginLeft="0dp"
            android:layout_marginRight="4dp">
            <TextView …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-xml android-recyclerview

16
推荐指数
1
解决办法
2277
查看次数

Android相对布局,按钮宽度使用重量

我已经使用layout_weight参数将按钮的宽度设置为总布局宽度的70%,但似乎我缺少一些重要的细节才能使它工作.

(另一个解决方案是以display.getWidth()编程方式工作,但它也不起作用,因为我不知道我的.xml应该是什么样子如果我选择设置宽度button.setWidth())

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_height="fill_parent" 
    android:layout_width="fill_parent"
    android:layout_weight="1.0">
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="15px"  
        android:id="@+id/userVersionTextViewNew"
        android:gravity="center"
        android:layout_centerVertical="true"/>
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="15px"
        android:gravity="center"
        android:layout_above="@id/userVersionTextViewNew"
        android:id="@+id/userSoftSerialNumberTextView"/>
    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/logo_200"
        android:layout_above="@id/userSoftSerialNumberTextView"
        android:layout_centerHorizontal="true"/>    
    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:textSize="15px"
        android:gravity="center"
        android:layout_below="@id/userVersionTextViewNew"
        android:id="@+id/dummyTextView"/>       
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/loginButton"
        android:text="???????"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/dummyTextView"
        android:layout_weight="0.7"/>
    <Button
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:id="@+id/demoLoginButton"
        android:text="??????????? ?????"
        android:layout_centerHorizontal="true"
        android:layout_below="@id/loginButton"
        android:layout_weight="0.7"/>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

layout android button width

13
推荐指数
4
解决办法
8万
查看次数

Android TableLayout高度不会填满整个屏幕

我有一个线性布局,里面只有一个TableLayout.表格布局还有两行,每行两列.First Table Row有两个图像.Second Table Rows有两个按钮.

但这并没有显示在整个屏幕上,而只是显示在前半部分或者可能取决于图像高度.两个图像实际上是相同的文件,但显示不同的宽度.请帮助...这是布局文件

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical">

    <TableLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:layout_weight="1"
        android:stretchColumns="*">

        <TableRow
            android:layout_height="fill_parent">

            <ImageView
                android:id="@+id/tp_image"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:layout_weight="0.9"
                android:scaleType="fitXY"
                android:src="@drawable/images" />

            <ImageView 
                android:id="@+id/s_image"
                android:src="@drawable/images"
                android:layout_width="0dip"
                android:layout_height="fill_parent"
                android:scaleType="fitXY"
                android:layout_weight="0.1"
                />
        </TableRow>
        <TableRow >
            <Button 
                android:id="@+id/button_LC"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/button_LC"/>
            <Button 
                android:id="@+id/button_RC"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:text="@string/button_RC"/>
        </TableRow>
    </TableLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android tablelayout

11
推荐指数
1
解决办法
9981
查看次数

阻止ImageView在屏幕外推送视图

我有一个线性布局,其中包含一个imageview和另一个线性布局,它是屏幕上的底栏.我在项目的其他地方使用底栏,我不认为这是问题所在.

问题是imageview占据了整个屏幕.图像本身没有,但视图确实如此.我似乎无法弄清楚这一点.正如你在我的xml中看到的那样,我没有在图像视图中使用fill_parent,我已经为图像尝试了所有可能的scaleType.

有什么建议?此外,如果它有助于我构建Android API 8

编辑:我已经更改了下面的xml,以便您可以完全使用我所写的内容.(这是我在图像视图中使用的图像:http://i.imgur.com/qN5aT.jpg)

<?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:background="#FFFFFF" >

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:scaleType="fitStart"
        android:src="@drawable/quote_sample_img" />

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom"
        android:orientation="vertical" >

        <TextView
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:text="This is text" />
    </LinearLayout>

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

http://i.imgur.com/m3msH.png (抱歉没有足够的声望发布实际图片)

android imageview android-layout android-imageview

8
推荐指数
1
解决办法
4763
查看次数

Android布局重量不像我想的那样工作

以下android:layout_weight是什么意思?

我有这个:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="fill_parent"
    android:orientation="horizontal" >

    <Button
        android:id="@+id/buttonToastSimple"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="English Toast" />

    <Button
        android:id="@+id/buttonToastFancy"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:text="French Toast" />

</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

链接告诉我buttonToastFancy将占用大小的四分之三(3 /(3 + 1),但反之亦然.按照Eclipse /我的AVD,buttonToastSimple占据屏幕大小的四分之三.

我究竟做错了什么?

android-layout

8
推荐指数
1
解决办法
1万
查看次数

Spinner下拉高度以匹配父级

是否可以调整Spinner下拉高度以填满整个屏幕.现在我有3个项目,我动态添加到微调器适配器,但这些只覆盖屏幕的一半.我现在拥有的是这样的:

在此输入图像描述

我想要的是这样的:

在此输入图像描述

我可以添加空项目,但这不能解决不同屏幕尺寸的问题

我试图在微调器上实现一个样式,但它没有用

<style name="MyCustomSpinner" parent="Widget.AppCompat.Spinner.DropDown">
    <item name="android:dropDownHeight">match_parent</item>
</style>
Run Code Online (Sandbox Code Playgroud)

UPDATE

我在动作栏和微调器之间有一个视图,所以我不能layout_weight=1用于我的微调器

android android-spinner

8
推荐指数
1
解决办法
2276
查看次数