【问题标题】:show Imageview at distance 30% from top of the screen android在距屏幕顶部 30% 处显示 Imageview android
【发布时间】:2015-01-23 11:24:46
【问题描述】:

我有一个启动画面,它在屏幕中心的Imageview 中显示应用程序徽标。

我需要在距离屏幕顶部 30% 的地方显示 imageview,这样底部 70% 的屏幕看起来是空的

我有关于 padding 的想法,但不知道如何在这种情况下使用 %( percent )

<ImageView
        android:id="@+id/img_splashlogo"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true"
        android:contentDescription="SplashImage"
        android:layout_margin="20dip"
        android:src="@drawable/app_logo_splash" />

【问题讨论】:

    标签: android imageview padding


    【解决方案1】:

    这是您可以使用的代码,将图像置于线性布局中,然后使用此代码

    LinearLayout ll = new LinearLayout(this);
    ll.setOrientation(LinearLayout.VERTICAL);
    LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(
         LinearLayout.LayoutParams.FILL_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT);
    layoutParams.setMargins(30, 20, 30, 0);
    Button okButton=new Button(this);
    okButton.setText("some text");
    ll.addView(okButton, layoutParams);
    

    【讨论】:

    • 我已经有线性布局.in xml ..我可以使用它还是需要在java代码中创建?
    • 您需要在与初始屏幕视图链接的所需 java 文件中使用此代码
    • 或另一件事首先尝试在图像顶部添加和不可见视图,然后设置图像,然后通过 android:visibility="invisible" 和 android:visibility="invisible" 为可见图像顶部赋予 0.3 权重: weight="0.30" 到初始图像顶部的视图
    【解决方案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"
            android:background="@drawable/app_splash" >
    
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.30"
                android:gravity="center"
                android:orientation="vertical">
    
             <ImageView
                android:id="@+id/img_splashlogo"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:contentDescription="SplashImage"
                android:layout_margin="20dip"
                android:src="@drawable/app_logo_splash" />
    
    
            </LinearLayout>
    
          <View 
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_width="0.70"
                android:background="@android:color/transparent"/>
    
        </LinearLayout>
    

    【讨论】:

    • 你能帮个忙吗..我发布了一个问题,但仍然没有人回答......在这种情况下你能帮忙吗..
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2021-10-10
    • 2015-10-23
    • 1970-01-01
    • 1970-01-01
    • 2013-01-14
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多