Good day, I would like to ask what's the difference between creating a tablet layout variation and creating a folder for layouts (like: "res/layout-w600dp/" )?
I'm so sorry I'm new in making android app for small (cellular phones/android phones) together with large(tablets) devices.
Can anyone help me, please? I'm really having a trouble on what to do to have layout for tablets. I don't know if the layout for tablets will be automatically displayed when app is run on tablet or I have to put some code in the java part. I've read some documentations but I can't fully understand it. sorry.
Thank you for your help.
If you have two layout files:
res/layout/
activity_main.xml
res/layout-sw600dp/
activity_main.xml
And you have an activity that calls setContentView(R.layout.activity_main)
, you don't have to do anything else: the first version will be loaded on phones and the second will be loaded on tablets.
If each layout file has views with the same ids (maybe they're just arranged or sized differently), then you can just do whatever logic you want and it will work with both.
Normally, though, the tablet file will include views that the phone version does not. In that case, you should check to see if those views exist before trying to use them. Imagine that the tablet version has a view android:id="@+id/right_panel"
and the phone version does not. You might write:
View rightPanel = findViewById(R.id.right_panel);
if (rightPanel != null) {
// do something for tablets
}