相关疑难解决方法(0)

Android:如何使LinearLayout中的所有元素都相同?

我想创建一个对话框来显示视频标题和标签.在文本下面,我想添加按钮View,Edit和Delete,并使这些元素的大小相同.有谁知道如何修改.xml布局文件,以使LinearView中的元素大小相同?

当前布局文件如下所示:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="wrap_content" 
    android:orientation="vertical">

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

          <TextView 
              android:layout_width="wrap_content" 
              android:layout_height="wrap_content" 
              android:id="@+id/txtTitle" android:text="[Title]" >
          </TextView>

          <TextView 
              android:layout_width="wrap_content"
              android:layout_height="wrap_content" 
              android:id="@+id/txtTags"            
              android:text="[Tags]" >
          </TextView>

    </LinearLayout>

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

        <Button 
           android:layout_width="wrap_content" 
           android:layout_height="wrap_content" 
           android:id="@+id/btnPlay" 
           android:text="View">
        </Button>

        <Button 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/btnEdit" 
            android:text="Edit">
        </Button>

        <Button 
            android:layout_width="wrap_content" 
            android:layout_height="wrap_content" 
            android:id="@+id/btnDelete" 
            android:text="Delete">
        </Button>

    </LinearLayout>

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

如果有人能通过修改粘贴的文件内容来显示解决方案,我将不胜感激.

谢谢!

layout android

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

android编程方式的布局权重

我在布局xml上硬编码layout_weight.但是现在我想从java代码中给出layout_weight和weightSum.

我们如何从班上做到这一点?

 <LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    android:weightSum="25" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="5"
        android:background="#F51215"
        android:paddingLeft="5dip"
        android:text="5" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="20"
        android:background="#1AC92B"
        android:paddingLeft="5dip"
        android:text="20" />
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

android android-layout android-linearlayout

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

防止 ScrollView 占用过多高度

我试图防止 ScrollView 在屏幕底部占用太多空间,因为它会阻止我的两个按钮显示。我也不想手动设置 ScrollView 的高度。

<LinearLayout
   android:layout_width="fill_parent"
   android:layout_height="fill_parent"
   android:orientation="vertical">
   <LinearLayout
      ...
      android:orientation="horizontal">
        <Button .../>
        <TextView .../>
        <Button .../>
   </LinearLayout>
   <ScrollView
      android:layout_width="math_parent"
      android:layout_height="wrap_content">
      <ImageView .../>
      <ImageView .../>
      <ImageView .../>
   </ScrollView>
   <LinearLayout
      ...
      android:orientation="horizontal">
        <Button .../>
        <Button .../>
   </LinearLayout>
</LinearLayout>
Run Code Online (Sandbox Code Playgroud)

这是我的布局的通用版本。发生的情况是,无论其中有多少项,ScrollView 都会一直延伸到屏幕底部。这会导致屏幕底部的两个按钮不可见。

如果不手动设置 ScrollView 的高度,如何阻止这种情况发生?

我已经使用了android:layout_height="wrap_content"我所有的观点。

这不是应该自动分配视图的高度以适应屏幕的高度吗?

(想包含图片,但我的代表还不够高(-_- ))

height android scrollview

5
推荐指数
1
解决办法
3339
查看次数

如何创建 Step wise - Android 中的进度条

我想将用户的声音注册为 3 次输入。为此,我想创建一个 UI(XML文件),当第一次录制完成时,它会通过从第 1 步移动到第 2 步来制作动画,这将由开始停止按钮控制。并最终进入第 3 步..... 像这样 -

在此处输入图片说明

我不知道如何向谷歌解释这个!请帮忙!!

android android-progressbar

2
推荐指数
1
解决办法
4833
查看次数

ScrollView滚动,但不会完全显示其内容

我使用此代码将我的布局划分为2个滚动视图

<?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" >

<RelativeLayout

    android:layout_width="match_parent"
    android:layout_height="0px"
    android:background="@drawable/ashokb"
    android:layout_weight="4" >
<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_centerHorizontal="true"
    android:layout_centerVertical="true" 
    android:background="@drawable/flagc">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" 
        android:layout_gravity="center">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:gravity="center"
        android:orientation="horizontal" >

        <TextView
            android:id="@+id/textView1"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:text="Large Text"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:textColor="#000000" />

        <Button
            android:id="@+id/button1"
            android:layout_width="50dp"
            android:layout_height="50dp"
            android:layout_marginLeft="-50dp"
            android:background="@drawable/ic_menu_share" />

    </LinearLayout>

    <TextView
            android:id="@+id/textView5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:text="Medium Text"
            android:textColor="#000000" 

            android:gravity="center"
            android:textAppearance="?android:attr/textAppearanceMedium" />

  </LinearLayout>
</ScrollView>
</RelativeLayout>

<RelativeLayout

    android:layout_width="match_parent"
    android:layout_height="0px"
    android:background="@drawable/ashokb"
    android:layout_weight="1" >

    <ScrollView
        android:id="@+id/scrollView2"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_centerHorizontal="true"
        android:layout_centerVertical="true" > …
Run Code Online (Sandbox Code Playgroud)

android textview android-layout android-linearlayout android-scrollview

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

线性布局匹配父级或权重在协调器布局中不起作用

<?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="com.now.sexyfacechanger.Activity_PhotoOrGallery">

    <include layout="@layout/content_activity__photo_or_gallery" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:orientation="horizontal">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_camera"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_camera"
            android:layout_weight="1"/>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/fab_gallery"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:src="@android:drawable/ic_menu_gallery"
            android:layout_weight="1"/>

    </LinearLayout>


</android.support.design.widget.CoordinatorLayout>
Run Code Online (Sandbox Code Playgroud)

这是android studio设计中的视图,显示的线性布局与父级匹配:

在此处输入图片说明

但是输出:

在此处输入图片说明

线性布局与父布局不匹配,或者我怀疑应用于两个浮动按钮的 layout_weight 在协调器布局中不起作用。

android android-linearlayout android-layout-weight android-coordinatorlayout android-layoutparams

0
推荐指数
1
解决办法
1904
查看次数