【发布时间】:2014-03-24 17:35:10
【问题描述】:
我正在尝试为我的 android 应用创建线性布局。在这个线性布局内部还有另外两种布局,一种是相对布局,另一种是线性布局。这两个布局的权重为 1。当我在 graphics_layout 查看布局时,一切看起来都很好。但是当我在手机或虚拟设备上运行我的应用时,我只会看到一个空布局。
这是应该的样子(实际上是graphic_layout的截图):
这是它在虚拟设备和我的手机上的外观:
这是我的 xml 代码:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#EEEEEE"
android:orientation="vertical"
android:paddingLeft="16dp"
android:paddingRight="16dp"
tools:context="xx.xx.counter.MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2" >
<ProgressBar
android:id="@+id/progressBar2"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:progressDrawable="@drawable/cpb"
android:rotation="270" />
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerInParent="true"
android:text="@string/number"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="70sp" />
</RelativeLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="vertical" >
<Button
android:id="@+id/button2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/button2"
android:visibility="gone" />
<ProgressBar
android:id="@+id/progressBar1"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:rotation="180" />
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/number" />
</LinearLayout>
</LinearLayout>
这里是cpb.xml的代码:
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:id="@android:id/background">
<shape
android:innerRadiusRatio="3.5"
android:shape="ring"
android:thicknessRatio="60.0"
android:useLevel="false">
<gradient
android:startColor="#AAAAAA"
android:centerColor="#AAAAAA"
android:endColor="#AAAAAA"
android:type="linear"/>
</shape>
</item>
<item android:id="@android:id/progress">
<shape
android:innerRadiusRatio="4"
android:shape="ring"
android:thicknessRatio="20.0">
<gradient
android:startColor="#ff8800"
android:centerColor="#ff8800"
android:endColor="#ff8800"
android:type="linear"/>
</shape>
</item>
</layer-list>
如果我将父线性布局的高度和宽度从 fill_parent 或 match_parent 更改为 wrap_content,它看起来并不像我想要的那样。但是我在运行应用程序时可以看到一些东西,所以我认为这不是 onCreate() – Methode 的问题。
那么我的布局有什么问题,我该怎么做才能让它看起来像我想要的那样?
【问题讨论】:
标签: android android-layout layout android-xml