Previewing widgets in android studio preview mode

Inflating things this way seems to work for the preview:

public FlightOutboundInbound(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
}

private void init() {
    setWeightSum(3);
    setBackgroundResource(R.drawable.dark_blue_border_rect);
    setOrientation(HORIZONTAL);

    LayoutInflater inflater = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    inflater.inflate(R.layout.widget_flight_outbound_inbound, this, true);
    ButterKnife.bind(this);
}

But inflating things using the static view does not seem to work.

Source: http://stackoverflow.com/questions/17296552/preview-layout-with-merge-root-tag-in-intellij-idea-android-studio

<merge 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"
    tools:parentTag="LinearLayout"
    tools:orientation="horizontal">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Some text"
        android:textSize="20sp"/>

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Some other text"/>
</merge>

Leave a Reply

Your email address will not be published. Required fields are marked *