Layout Layers? Z-Axis

Can I control the z axis in android?

Use FrameLayout, not RelativeLayout or LinearLayout.

Anyway in Android having Views in top of others really makes no sense. Use View.setVisibility(View.GONE) to tell Android to not draw a View (it won't reserve space for it) and View.setVisibility(View.VISIBLE) to make it draw it.

Defining Z order of views of RelativeLayout in Android

The easiest way is simply to pay attention to the order in which the Views are added to your XML file. Lower down in the file means higher up in the Z-axis.

Edit:
This is documented here and here on the Android developer site. (Thanks @flightplanner)

Scroll views in framelayout over z-axis

It looks like one can choose between different 'cards' which are layered on top of each other.

Android has a StackView widget that offers this UI. You tend to see it more in app widgets, as typical Android app widgets like Photo Gallery and YouTube employ a StackView.

Here is a sample project demonstrating the use of a StackView in a traditional UI, not in an app widget.

How to control the z axis of individual Mapbox features inside the same layer?

here's an example with explanations.
You should set the properties symbolZOrder and symbolSortKey when defining the symbol layer.

symbolZOrder accept one of the following as argument:

  // SYMBOL_Z_ORDER: Controls the order in which overlapping symbols in the same layer are rendered

/**
* If symbol sort key is set, sort based on that. Otherwise sort symbols by their y-position relative to the viewport.
*/
public static final String SYMBOL_Z_ORDER_AUTO = "auto";
/**
* Symbols will be sorted by their y-position relative to the viewport.
*/
public static final String SYMBOL_Z_ORDER_VIEWPORT_Y = "viewport-y";
/**
* Symbols will be rendered in the same order as the source data with no sorting applied.
*/
public static final String SYMBOL_Z_ORDER_SOURCE = "source";

so if you wish to control the symbols based on some logic you should use the SYMBOL_Z_ORDER_AUTO value.

then you can set the symbolSortKey to some float value.

        Style.OnStyleLoaded onStyleLoaded = style -> {
style.addLayer(new SymbolLayer(SYMBOLS_LAYER, SYMBOLS_SOURCE)
.withProperties(
iconImage(step(zoom(),
literal("marker_public_base"),
stop(6, get("icon")))),
iconIgnorePlacement(true),
iconAllowOverlap(true),
iconSize(interpolate(
linear(), zoom(),
stop(0, MARKER_SYMBOL_SIZE * .13),
stop(5, MARKER_SYMBOL_SIZE * .33),
stop(9, MARKER_SYMBOL_SIZE))),
iconAnchor(ICON_ANCHOR_BOTTOM),
textField(get("title")),
textSize(interpolate(
linear(), zoom(),
stop(5.9, 0),
stop(6, SYMBOL_TEXT_SIZE * .4),
stop(7, SYMBOL_TEXT_SIZE * .7),
stop(11, SYMBOL_TEXT_SIZE))),
textOptional(true),
textHaloColor("#ffffff"),
textHaloWidth(1f),
textHaloBlur(1f),
textAnchor(TEXT_ANCHOR_TOP),
symbolZOrder(SYMBOL_Z_ORDER_AUTO),
symbolSortKey(get("zIndex"))
));

where


points.forEach(point -> {
Feature feature = Feature.fromGeometry(com.mapbox.geojson.Point.fromLngLat(point.lon, point.lat));
feature.addStringProperty("id", point.id);
feature.addNumberProperty("zIndex", point.isPublic? 0f : point.isSearchResult? 2f : 1f);
feature.addStringProperty("title", point.name);
feature.addStringProperty("icon", getIconImageID(point.category, point.isPublic, point.visited));

symbolsFeatures.add(feature);
});

Layer is rotating in x/y-axis instead of z-axis

I was about to answer but you preempted me! Anyway here is what I was going to say (it really addresses your last point)

The main reason for unpredictable behaviour is that you are setting the frame property on a transformed object. This you cannot do - Apple warns against it*: the frame property will return undefined results after a transform has been applied.

SO you should not do this:

 //_imageLayer.frame = layerFrame;

but setting bounds and center properties (position in the case of CALayers) continues to work as expected, so instead you can do something like this:

   _imageLayer.bounds = (CGRect){0,0,min,min};
_imageLayer.position = self.center;


* see the documentation for the frame property in UIView:

Warning: If the transform property is not the identity transform, the value of this property is undefined and therefore should be ignored.

Placing/Overlapping(z-index) a view above another view in android

You can't use a LinearLayout for this, but you can use a FrameLayout. In a FrameLayout, the z-index is defined by the order in which the items are added, for example:

<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/my_drawable"
android:scaleType="fitCenter"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:padding="5dp"
android:text="My Label"
/>
</FrameLayout>

In this instance, the TextView would be drawn on top of the ImageView, along the bottom center of the image.

Is it possible to create a bound between 2 views so their z-index is always next to each other?

I've managed to find a working solution for this — it's possible to observe my superview.layer.sublayers for any changes. Then it's just a matter of making sure the layer of my viewA1 is always near the layer of viewA2.



Related Topics



Leave a reply



Submit