繁体   English   中英

Android Eclipse XML

[英]Android Eclipse XML

我正在开发此测验,但这个设计有问题...

GuessButton.xml

<?xml version="1.0" encoding="utf-8"?>
<Button xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/newGuessButton"
     android:textColor="#FFFFFF"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:background="@drawable/buttonshape"
    android:layout_weight="1"
    android:shadowColor="#000000"
    android:shadowDx="5"
    android:shadowDy="2"
    android:shadowRadius="5" >

</Button>

buttonshape.xml

<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle" >
<corners
android:radius="50dp"
/>
<gradient
android:gradientRadius="200"
android:centerX="35%"
android:centerY="50%"
android:centerColor="#5E0707"
android:startColor="#E80909"
android:endColor="#000000"
android:type="radial"
/>
<size
android:height="50dp"
/>
<stroke
android:width="2dp"
android:color="#878787"
/>
</shape>

按钮出现的主要xml:

<TableLayout
            android:id="@+id/buttonTableLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="1"
            android:stretchColumns="*" >

            <TableRow
                android:id="@+id/tableRow0"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >
            </TableRow>

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >
            </TableRow>
        </TableLayout>

图像出现的xml代码:

 <ImageView
            android:id="@+id/faceImageView"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:adjustViewBounds="false"
            android:scaleType="centerInside" />

为了使图像适合所有设备,因为它们位于资产文件夹中。在代码中,我这样做了:

 public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.kuizi);
 DisplayMetrics displaymetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
    int width = displaymetrics.widthPixels;
    int h = faceImageView.getLayoutParams().height;
    h = width/2;
    faceImageView.getLayoutParams().height = h;

因此,在我测试过的所有设备中,它都能很好地工作...这是一个屏幕截图:

好的

但是在我的朋友手机上看起来像这样:

坏

这么小的图像和错误的按钮...我不知道为什么...我在互联网上搜索了一个星期却什么都没找到...有人可以帮我吗...在此先谢谢...我真的将感谢您的帮助...

这很困难,因为您没有发布整个布局...但是请尝试这种方法。

尝试将图像包装在RelativeLayout 在这种情况下, RelativeLayout应该调整大小并适应内容。

<RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
  >

 <ImageView
            android:id="@+id/faceImageView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:adjustViewBounds="false"
            android:scaleType="centerInside" />
</RelativeLayout>

另一个解决方案可能是不使用表,而是使用LinearLayout + weight属性。 对我来说,桌子更难使用,但取决于您!

我希望这有帮助!

我完成了,做了两个布局,第一个布局中填充了图像,第二个布局中放置了所有其他内容,所以现在屏幕的前半部分是图片,下半部分是其他内容,...

谢谢大家...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM