Android layout 图像赢得';带android的t中心:布局\u中心水平
使用代码“android:layout\u centerHorizontal”我的图像不会居中,即使使用重力也无法解决它。我的relativelayout和scroll视图中是否有其他方式或输入错误 屏幕尺寸768x1280 nexus api23 我没有安卓版本4的问题,也许这是api相关的?因为我的最小sdk是android版本2 代码如下:Android layout 图像赢得';带android的t中心:布局\u中心水平,android-layout,android-xml,Android Layout,Android Xml,使用代码“android:layout\u centerHorizontal”我的图像不会居中,即使使用重力也无法解决它。我的relativelayout和scroll视图中是否有其他方式或输入错误 屏幕尺寸768x1280 nexus api23 我没有安卓版本4的问题,也许这是api相关的?因为我的最小sdk是android版本2 代码如下: <?xml version="1.0" encoding="utf-8"?> <ScrollView xmlns:android=
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:fillViewport="true"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context="com.capstone.jmilibraryapp.Login">
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="@+id/etUsername"
android:hint="Enter Sr-Code"
android:layout_below="@+id/imageView3"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_centerHorizontal="true"
android:layout_width="500dp"
android:layout_height="200dp"
android:src="@drawable/jmilogo"
android:id="@+id/imageView3"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<EditText
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="@+id/etPassword"
android:inputType="textPassword"
android:hint="Password"
android:layout_below="@+id/etUsername"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="300dp"
android:layout_height="wrap_content"
android:id="@+id/bLogin"
android:text="Log In"
android:layout_below="@+id/etPassword"
android:layout_alignLeft="@+id/etPassword"
android:layout_alignStart="@+id/etPassword" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Log In as Guest"
android:id="@+id/guest"
android:layout_marginTop="20dp"
android:layout_below="@+id/bLogin"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Log In as Guest"
android:id="@+id/testinguser"
android:layout_marginTop="20dp"
android:layout_below="@+id/guest"
android:layout_centerHorizontal="true"
/>
</RelativeLayout>
</ScrollView>
可能您的图像与ImageView的比例不同,您可以在设备的开发者工具中检查它是否启用showLayoutBounds。您将看到imageView的实际大小
为了解决这个问题,您可以使ImageView与ImageView成比例,或者为ImageView添加一个scaleType=“fitCenter”。试试下面的xml,这是我的工作
你想要什么??我的意思是你想把你的imageview放在编辑文本后面???@uttampanchasara先生,我添加了一张图片,很抱歉我的回复太晚了,我在家里的互联网连接太慢了。先生,我尝试了你的代码,我得到了这个错误“java.lang.RuntimeException:无法启动活动组件信息{com.capstone.jmilibraryapp/com.capstone.jmilibraryapp.Login}”:java.lang.ClassCastException:android.support.v7.widget.AppCompatImageView无法在android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2416)处强制转换为android.widget.EditText也许我对appcompactview有问题?尝试使用支持库7 ur使用旧版本EAH可能我应该更改任何图像大小吗?我已经更新了我的帖子,顺便问一下,也许我对api版本有问题?@earlcabanig从您的ImageView中删除android:layout\u alignParentLeft=“true”android:layout\u alignParentStart=“true”。这是答案,我投了赞成票,但似乎可以公开看到分数,因为我的声誉低于15。顺便说一下,谢谢^^
<?xml version="1.0" encoding="utf-8"?>
<ScrollView 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:layout_centerHorizontal="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:orientation="vertical">
<ImageView
android:id="@+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:scaleType="fitCenter"
android:src="@drawable/school" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_weight="1">
<EditText
android:id="@+id/etUsername"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:hint="Enter Sr-Code" />
<EditText
android:id="@+id/etPassword"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_below="@+id/etUsername"
android:layout_centerHorizontal="true"
android:hint="Password"
android:inputType="textPassword" />
<Button
android:id="@+id/bLogin"
android:layout_width="300dp"
android:layout_height="wrap_content"
android:layout_alignLeft="@+id/etPassword"
android:layout_alignStart="@+id/etPassword"
android:layout_below="@+id/etPassword"
android:text="Log In" />
<TextView
android:id="@+id/guest"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/bLogin"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Log In as Guest"
android:textAppearance="?android:attr/textAppearanceSmall"/>
<TextView
android:id="@+id/testinguser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/guest"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dp"
android:text="Log In as Guest"
android:textAppearance="?android:attr/textAppearanceSmall"/>
</RelativeLayout>
</LinearLayout>
</ScrollView>