Tag: 布局

ImageView填充父宽度或高度,但保持宽高比

我有一个方形图像(虽然这个问题也适用于矩形图像)。 我希望尽可能大地展示图片,如有必要可以展开图片,以填充父母,同时保持高宽比。 图像比ImageView小。 问题是,我无法拉伸图像,并“匹配”ImageView的高度和宽度。 这是我的XML布局文件: <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content" android:padding="10dp"> <ImageView android:id="@+id/image" android:layout_width="fill_parent" android:layout_height="fill_parent" android:adjustViewBounds="true" android:scaleType="fitCenter" android:layout_marginTop="10dp"/> <TextView android:id="@+id/name" android:layout_below="@id/image" android:layout_alignLeft="@id/image" android:layout_marginTop="20dp" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="18dp"/> <TextView android:id="@+id/name2" android:layout_below="@id/name" android:layout_width="fill_parent" android:layout_height="wrap_content" android:textSize="14dp"/> </RelativeLayout> 我已经使用fill_parent , wrap_content和多个缩放types的许多组合: fitCenter , fitStart , fitEnd , centerInside ,它们都以正确的高宽比绘制图像,但是没有一个实际缩放图像和ImageView本身 ,导致TextViews被一路推下屏幕,ImageView里面的空白,图像没有缩放或图像被裁剪。 我不能完全确定这个合适的组合。

在Android中垂直居中视图

我正在尝试使用以下布局将View垂直居中在屏幕上: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <EditText android:text="example text" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_gravity="center_vertical" /> </LinearLayout> 但是它不起作用。 EditText仍然在屏幕的顶部。 有人能解释我在这里做错了吗? 注意:如果我将center_horizontal添加到layout_gravity属性,那么它会将其水平居中,但仍不会垂直居中。 更新:使用android:gravity="center_vertical"上的父母工作。 我仍然不明白为什么android:layout_gravity="center_vertical"的孩子没有工作。

Android:findviewbyid:当view不在setContentView调用的同一个布局上时,通过id查找view

我有一个从MapActivity扩展的活动MyActivity。 在包含布局的.xml文件中,我只能包含MapView <com.google.android.maps.MapView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/trail_map_view" android:layout_width="fill_parent" android:layout_height="fill_parent" android:clickable="true" android:apiKey="key" /> 但是我需要find另一个位于另一个.xml文件中的视图。 不幸的是,findViewById返回null。 我怎样才能得到我正在寻找的视图? 非常感谢!

条件扩展模板

我使用Symfony 2和Twig,我的问题非常简单: 在一个视图中,我想扩展一个基于variables的布局。 如果该variables为false我想扩展UdoWebsiteBundle::layout.html.twig ,如果它是true我想扩展UdoWebsiteBundle::layout_true.html.twig 。 这是我试过的代码: {% block layout_extender %} {% if intro == 'false' %} {% extends 'UdoWebsiteBundle::layout.html.twig' %} {% else %} {% extends 'UdoWebsiteBundle::layout_true.html.twig' %} {% endif %} {% endblock %} 我得到这个错误: 第7行的“UdoWebsiteBundle:home:home.html.twig”中禁止使用多个扩展标签 有没有其他办法可以做到这一点?

CSS 100%高度布局

我知道这是一个普遍的问题,我查找了一些解决scheme,但是找不到我正在寻找的东西。 我想将其转换为无表格布局。 注意:页眉和页脚必须设置为固定的像素高度(50px是可以的)。 我遇到的主要问题是,我无法在中间得到那个“大箱子”,performance得和表格一样。 有可行的解决scheme,可变长度的内容(文本,图像),但我希望这个盒子看起来像一个盒子 – 有边框,圆angular和所有的行为。

自定义视图与布局

好, 我想要做的是在默认的布局main.xml中embedded一个自定义视图: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <com.lam.customview.CustomDisplayView android:id="@+id/custom_display_view1" android:layout_width="fill_parent" android:layout_height="fill_parent" /> <LinearLayout android:orientation="horizontal" android:layout_width="fill_parent" android:layout_height="wrap_content"> <Button android:id="@+id/prev" android:layout_width="0dip" android:layout_height="wrap_content" android:layout_weight="50" android:textAppearance="?android:attr/textAppearanceSmall" android:text="@string/prev" /> </LinearLayout> </LinearLayout> 你可以看到这个类叫做com.lam.customview.CustomDisplayView,其id为custom_display_view1。 现在在com.lam.customview.CustomDisplayView类,我想使用另一个名为custom_display_view.xml的布局,因为我不想以编程方式创build控件/小部件。 custom_display_view.xml只是一个button和一个图像,我想根据一定的条件改变其内容: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:id="@+id/display_text_view1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <ImageView android:id="@+id/display_image_view1" android:layout_width="wrap_content" android:layout_height="wrap_content"> </ImageView> </LinearLayout> 我试图做到: 1) […]

从布局xml文件旋转ImageView源

我在我的布局中有这个ImageView: <ImageView android:layout_width="fill_parent" android:layout_height="wrap_content" android:contentDescription="@string/image_divider" android:paddingBottom="8dp" android:paddingTop="4dp" android:scaleType="fitXY" android:src="@android:drawable/divider_horizontal_textfield" /> 这是一个水平分隔线。 我想旋转90度,所以我有一个垂直分频器。 有没有任何可能的方式在这里从布局,而不是活动课?

Android的InputType布局参数 – 如何允许负小数?

我有一个布局,有三个字段的input三个地图坐标。 到现在为止还挺好。 我在布局中使用android:inputType =“numberDecimal”。 input字段时,用户将获得数字键盘。 还好。 但是,当需要input负值坐标时,没有明显的方法来做到这一点。 23.2342工作正常。 232.3421工作正常。 -11.23423无法input – 无法input前导负号,甚至无法将坐标包裹在()中。 我敢肯定,我可以去改变这个直接的文本inputType的路线,然后使用正则expression式来validationinput的内容实际上是一个数字坐标,处理错误消息传回给用户,但我想而不是走那条路。 我已经Google和Stackoverflow这个问题几个小时没有运气。 有什么build议么?

如何把一个div在浏览器中心使用CSS?

如何使用CSS只在垂直和水平的浏览器的中心放置一个div? 确保它也可以在IE7上运行。 如果一切都失败了,我们可能会使用JavaScript,但是最后的select。

加载视图的布局参数被忽略

我试图写我自己的自定义View ,我有问题的LayoutParams 。 这个想法是扩展ViewGroup ( LinearLayout ) public class MyView extends LinearLayout{ public MyView(Context context, AttributeSet attrs) { super(context, attrs); } public MyView(Context context) { super(context); } public void putContent(){ setOrientation(HORIZONTAL); LayoutInflater inflater = (LayoutInflater)getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE); for (int i = 0; i < 5; i++){ View view = inflater.inflate(R.layout.item, null); TextView tv = (TextView)view.findViewById(R.id.item_text); tv.setText("Item " […]